IPv6 Launchipv6 ready

How to integrate SpamAssassin with Postfix 

The following tutorial is for Debian/Ubuntu based system, but will work on almost any other Linux distribution, presuming you have already configured postfix MTA.

Installing SpamAssassin

stan@datacentrix:~$ sudo apt-get install spamc spamassassin
stan@datacentrix:~$ sudo groupadd -g 5001 spamd
stan@datacentrix:~$ sudo useradd -u 5001 -g spamd -s /sbin/nologin -d /var/lib/spamassassin spamd
stan@datacentrix:~$ sudo mkdir /var/lib/spamassassin
stan@datacentrix:~$ sudo chown spamd:spamd /var/lib/spamassassin

Enabling SpamAssassin

The code above will install and create the spamassassin working space. Next we will need to do a basic configuration. Open the default configuration file (/etc/default/spamassassin for Ubuntu or relative for your OS), comment all lines which don't have a # symbol in the beginning and write following in the top of the file. The result should be:

stan@datacentrix:~$ sudo nano /etc/default/spamassassin

========= cut here ===============

OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir ${SAHOME} -s ${SAHOME}spamd.log"

# /etc/default/spamassassin
# Duncan Findlay

# WARNING: please read README.spamd before using.
# There may be security risks.

# Change to one to enable spamd

# Options
# See man spamd for possible options. The -d option is automatically added.

# SpamAssassin uses a preforking model, so be careful! You need to
# make sure --max-children is not set to anything higher than 5,
# unless you know what you are doing.

#OPTIONS="--create-prefs --max-children 5 --helper-home-dir"

# Pid file
# Where should spamd write its PID to file? If you use the -u or
# --username option above, this needs to be writable by that user.
# Otherwise, the init script will not be able to shut spamd down.

# Set nice level of spamd
#NICE="--nicelevel 15"

# Cronjob
# Set to anything, but 0 to enable the cron job to automatically update
# spamassassin's rules on a nightly basis

You can save the file with Ctrl+X and enter to confirm the filename.

Adding some rules to SpamAssassin

Edit the file /etc/spamassassin/local.cf - add this code to the top:

rewrite_header Subject [***** SPAM _SCORE_ *****]
required_score 5.0
#to be able to use _SCORE_ we need report_safe set to 0
#If this option is set to 0, incoming spam is only modified by adding some "X-Spam-" headers and no changes will be made to the body.
report_safe 0

# Enable the Bayes system
use_bayes 1
use_bayes_rules 1
# Enable Bayes auto-learning
bayes_auto_learn 1

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

It'll tell the SpamAssassin to mark the message as spam if the spam score is more or equal to 5.0, to append the result headers in the message and to rewrite the subject if its considered spam to [***** SPAM (5.7 for example) *****].

The last step is to start the SpamAssassin service:

stan@datacentrix:~$ sudo /etc/init.d/spamassassin start

Now SpamAssassin is configured and running in the system.

Connect SpamAssassin with Postfix MTA

Edit /etc/postfix/master.cf and add these lines:

smtp      inet  n       -       -       -       -     smtpd -o content_filter=spamassassin

spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e
/usr/sbin/sendmail -oi -f ${sender} ${recipient}

Then reload the postfix configuration with:

stan@datacentrix:~$ sudo service postfix reload

Now all incoming and outgoing messages will be checked with SpamAssassin.

Comments - How to integrate SpamAssassin with Postfix

Add Comment

Fill out the form below to add your own comments.

Insert Special:

Moderation is turned on for this blog. Your comment will require the administrators approval before it will be visible.

Tagged as: , , , , , , , , , , , ,

<Back | 1 | 2 | 3 | 4 | Next> Last>>