SpamAssassin on Ubuntu 16

Reading Time: 2 minutes

Today, let us try to setup SpamAssassin on Ubuntu 16.04.5 LTS. Just ensure you have access to root user via SSH.

$ apt-get install spamassassin spamc

Let us add a user for the spamd daemon.

$ adduser spamd --disabled-login

Edit the configuration settings at /etc/default/spamassassin. Make sure to make a full backup copy for spamassassin file.

From here, just follow the setup below:

# Comment ENABLED=0

# Add the line below, make sure these are place in one line only.
OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir /home/spamd/ -s /var/log/spamassassin/spamd.log"

# Change Cron from 0 to 1

Edit /etc/spamassassin/ to set up some anti-spam rules.

rewrite_header Subject ** SPAM _SCORE_ **
report_safe             0
required_score          5.0
use_bayes               1
use_bayes_rules         1
bayes_auto_learn        1
skip_rbl_checks         0
use_razor2              0
use_dcc                 0
use_pyzor               0

This will cause each email that scores 5.0 or greater to be marked with ** SPAM ** and the score in its subject line.

For example:

** SPAM 12.0** Test Email. Please do not reply. 

Most email clients already recognize the headers or text that SpamAssassin adds to incoming emails, but if you have a client that doesn’t, you can set up a filtering rule to send any message with ** SPAM ** in its subject line directly to your junk folder.

Tell Postfix to pass incoming messages to the anti-spam system for checking. To do so, edit /etc/postfix/ and add a content filter to your SMTP server:

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}

This tells the client to pass its completed checks to the default MTA (mail transfer agent, /usr/sbin/sendmail, i.e., the Postfix-Sendmail compatibility interface) for handoff to the MDA (mail delivery agent, Dovecot) for delivery.

Make sure to restart postfix service and enable spamassassin on boot then start spamassassin service.

$ systemctl restart postfix
$ systemctl enable spamassassin
$ systemctl start spamassassin

To check SpamAssassin’s startup status, run.

 systemctl list-units --type=service --all | grep spam

spamassassin.service will be listed as active/loaded if it’s running properly.

Now try sending your accounts on the server a couple of emails from an external account (Gmail,, whatever) and check the full message headers after you’ve received them. You should see some entries like this if everything is working correctly:

X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, etc. etc.

Great Job. 


Was this post helpful?

Leave a Reply

Close Menu