Learn How To Configure Spamassassin With Postfix on Ubuntu 16.04

November 13, 2019

Table of Contents

Spamassassin is a free and open-source mail filter written in Perl that is used to identify spam using a wide range of heuristic tests on mail headers and body text. It will save your mailbox from much unwanted spam emails.

Prerequisites

Before installing Spamassassin, you need to install and configure a mail transfer agent such as Postfix on your virtual private server. The following instructions are for using Spamassassin with Postfix.

Install Spamassassin.

apt-get install spamassassin spamc

Add a Spamassassin user.

adduser spamd --disabled-login

Setting Up Spamassassin

Edit the configuration settings at /etc/default/spamassassin.

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

Now we will edit /etc/spamassassin/local.cf 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

Configuring Postfix

Edit /etc/postfix/master.cf 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}

For the changes to take effect, restart Postfix.

systemctl restart postfix.service
systemctl enable spamassassin.service
systemctl start spamassassin.service

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!