CentOS 7 – Installing and configuring SpamAssassin

How to create virtual machines with VirtualBox

SpamAssassin is one of the most powerful spam filters that work with Postfix to filter all mails that may present a threat.

We will use it to filter all Postfix mails on our mail server (as we described in Chapter 4, Mail Server with Postfix, about how to get one up and running).

First, we need to install it using the default package manager:


$ sudo yum install spamassassin

Then it is installed. Now we move on to the configuration part:


$ sudo nano /etc/mail/spamassassin/local.cf

We have some lines that we need to make sure are in the file. So, we’d rather write them or uncomment them if they are commented:


rewrite_header Subject ***SPAM***
required_hits 5.0
report_safe 0
required_score 5

Next, we create a new user group and a user to manage the service:


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

Then we have our service well configured. We move on to the Postfix part, where we should make some minor changes to its master configuration file:


$ sudo nano /etc/postfix/master.cf

We need to go to the line of the SMTPD configuration and add the following line:


-o content_filter=spamassassin

Therefore, it should look like this:


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

After that, we add the following line:


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

We save the file and quit. Now we need to update the SpamAssassin rules by typing the following:


$ sudo sa-update --nogpg

Now, to make the change in the SpamAssassin service and the Postfix server, we need to restart it and then we are done:


$ sudo systemctl restart spamassassin
$ sudo systemctl restart postfix.service

Comments are closed.