Spam Filtering: Spamassassin for Postfix on Linux Debian 8

How to deal with SPAM if you operate VPS on Linux? Today we will show the installation of Spamassassin and its settings to suppress SPAM in incoming emails.

First, we install the extension itself.

apt-get install spamassassin spamc

We create user and group spamd, login directory and set permissions / ownership.

groupadd spamd
useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
mkdir /var/log/spamassassin
chown spamd:spamd /var/log/spamassassin

We will make configuration modification in /etc/default/spamassassin

ENABLED=1
OPTIONS="--create-prefs --max-children 5 --helper-home-dir --username spamd -H /var/log/spamassassin/ -s /var/log/spamassassin/spamd.log "
CRON=1

and at the same time we configure/etc/spamassassin/local.cf

rewrite_header Subject [***** SPAM _SCORE_ * ****]
report_safe 1
required_score 4.0
service spamassassin status

The result should be this:

Very essential is the line that displays

Loaded: loaded (/lib/systemd/system/spamassassin.service; enabled)

The service must be in enabled state, not disabled. If only status reported this:

Loaded: loaded (/lib/systemd/system/spamassassin.service; disabled< /span>)

It is necessary to start Spamassassin in the following way:

systemctl enable spamassassin.service

The service starts in the background and we can verify its progress using netstat -nlp4 | grep spam

How to configure Postfix to use Spamassassin as a filter for email messages

Edit the file /etc/postfix/master.cf

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

and at the end of the file the following directive:

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

Then we can complete Postfix restart:

service postfix restart


More resources: