SoFunction
Updated on 2025-03-10

Simple application of SpamAssassin

Here we will only talk about the simple application of SpamAssassin, which is to use SpamAssassin's rule set to mark spam as spam, and then use a policy on the client outlook to automatically transfer emails with spam characters to the spam directory.

See the article
CCERT Chinese spam filtering rule set
(/spam/sa/Chinese_rules.htm)

Test environment: redhat9.0
Prerequisites: qmail has been installed, the environment already built in this article is qmail+vpopmail+igeus

1: Install SpamAssassin
Installation method 1: Install directly through CPAN
perl -MCPAN -e shell 
install Mail::SpamAssassin

2: Compile and install it yourself
Download the latest version of the software

After decompression: #perl
# make
# make install

# Conduct a spam and non-spam test
In the spamassassin source file directory:
spamassassin -t <  > 
less 
spamassassin -t <  > 
less  
The file will contain the line "***SPAM*****" in a paragraph of the topic, but there is no in the file.
(Default read /etc/mail/spamassassin/configuration.)

If an error is reported during the make process, you can refer to this article to solve related problems http://blog./archives/2005/07/

3: Configuration file
# vi /etc/mail/spamassassin/

# How many hits before a message is considered spam.
required_hits           9.5

# Text to prepend to subject if rewrite_subject is used
rewrite_header Subject *** spam****

# Encapsulate spam in an attachment
report_safe             1

# Enable the Bayes system
use_bayes               1

# Enable Bayes auto-learning
bayes_auto_learn        1

# Enable or disable network checks
skip_rbl_checks         1
use_razor2              0
use_dcc                 0
use_pyzor               0

# Mail using languages used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_languages            all

# Mail using locales used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_locales              all

For SpamAssassin configuration files, please refer to SpamAssassin Configuration Guide (Chinese version)
(/references/?Action=Show&ID=9)

4: Download the Chinese Rule Set of Spam
wget -N -P /usr/share/spamassassin /spam/sa/Chinese_rules.cf

5: The combination of qmail and SpamAssassin

Compile qmail-spamc in the spamc directory of SpamAssassin
# cc -O -o qmail-spamc 
# install -m 755 qmail-spamc /var/qmail/bin

# ln -s /var/qmail/bin/qmail-queue /usr/bin/qmail-queue

Edit /etc/ As follows
127.:allow,RELAYCLIENT=""
:allow,QMAILQUEUE="/var/qmail/bin/qmail-spamc"

Then:
tcprules   < 

In the compile directory spamd directory
mv   /etc///spamd

Start spamd
/etc///spamd start

In this way, SpamAssassin will automatically judge spam based on the rule set, and mark the spam that is potentially possible as the tag of **** spam****. It is clear at a glance. As for how to set a policy for client outlook to automatically transfer spam, I don’t need to say anything.