How to install and integrate SpamAssassin with Postfix on a CentOS 6 VPS – Blog

Views: 2659

Microsoft Oulook’s spam filter is broken for a while now. I got sick of wasting time deleteing spam. So I installed SpamAssassin. the last time I used this it was OK. But needed to be taught not trash transliterated Hebrew words like “Mezuzot” since my other Business is producing such Judaica

tutorial we are going to set-up SpamAssassin on one of our CentOS 6 linux virtual servers and integrate it into our Postfix mailserver set-up so it can scan and mark the emails detected as SPAM.

What is SpamAssassin?

It is a program released under the Apache License 2.0 used for e-mail spam filtering based on content-matching rules.


As usual, make sure your CentOS 6 linux vps is fully up to date by executing:

## screen -U -S spamc-screen
## yum update


Install the SpamAssassin package using yum by running:

## yum install spamassassin


create spamfilter group used for the user that will run the spamassassin service

## groupadd spamfilter

create new user spamfilter with a home directory of /usr/local/spamassassin and add it to the spamfilter group you just created

## useradd -g spamfilter -s /bin/false -d /usr/local/spamassassin spamfilter
## chown spamfilter: /usr/local/spamassassin


next, configure spamassassin by editing /etc/mail/spamassassin/ and adding/setting the following

## vim /etc/mail/spamassassin/

## Required_hits: This determines the filter balance; the lower the score the more aggressive the filter.
# A setting of 5.0 is generally effective for a small organisation or a single user.
# Adjust the strictness score to your organization's needs - a large medical organisation might want  to let email items
# through that are trying to sell pharmaceuticals, so we might increase the level to a more modest 8.0.
required_hits 5
## Report_safe:  This line determines whether to delete the item or to move the item to the inbox whilst appending
# a spam notice to the subject line. The levels for this line are set to either a 1 or 0. A score of 1 will delete the spam item,
# whereas a score of 0 will send the item to the inbox and rewrite the subject line.
report_safe 0
rewrite_header Subject [**SPAM**]
## Required_score: This line sets the spam score for all email allowed through to your domain, with levels of certainty set from 0 to 5.
# Zero would be classified as a legitimate email item, whereas 5 would be an definite 'SPAM' item.  If we set the score to 3 we would catch a
# lot of unsolicited emails but quite a few false positives would still get through. For our example email server we will use the score of 5,
# but you can of course set this value according to your preference.
required_score 5.0

before we proceed with starting-up the spamassassin service, we need to make sure it runs with our newly created spamfilter user by editing /etc/sysconfig/spamassassin and setting-up the following:

## vim /etc/sysconfig/spamassassin

# Options to spamd
SPAMDOPTIONS="-d -c -m5 --username ${SUSER} -H ${SAHOME} -s ${SAHOME}/spamfilter.log"

with all that in place, we are ready to start and enable the spamassassin service on system startup using:

## service spamassassin start
## chkconfig spamassassin on


next thing you need to do is to actually integrate spamassassin into postfix so it can scan and mark the emails that were detected as SPAM. To achieve this we need to edit postfix configuration file. Edit

## vim /etc/postfix/

and add/edit the following lines:

smtp      inet  n       -       n       -       -       smtpd -o content_filter=spamassassin
spamassassin unix -     n       n       -       -       pipe user=spamfilter argv=/usr/bin/spamc -f -e  /usr/sbin/sendmail -oi -f ${sender} ${recipient}

then, restart postfix for the changes to take effect

## service postfix restart


To test if SpamAssassin actually works, you can simply send an email with subject XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X to some of your email accounts and once the email is received, check it’s headers and you should notice something like this:

X-Spam-Flag: YES
X-Spam-Level: **************************************************
X-Spam-Status: Yes, score=1000.0 required=5.0 tests=GTUBE,RCVD_IN_DNSWL_NONE,
    TVD_SPACE_RATIO autolearn=no version=3.3.1

This means that SpamAssassin is doing it’s job.

Implementing SpamAssassin to the mailserver set-up with virtual users and domains using Postfix and Dovecot adds another nice feature to the mail server set-up.


Source: How to install and integrate SpamAssassin with Postfix on a CentOS 6 VPS – Blog

Leave a Reply