How to install SpamAssassin on a virtual server with CentOS 6

spamassassin

SpamAssassin is an Open Source mail filter, written in Perl, used for e-mail spam filtering based on content-matching rules. It can be used on a wide variety of email systems including sendmail.

SpamAssassin can easily be installed via RPM on a virtual private server with CentOS 6 using the following steps:

Enable EPEL repository:

vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
yum clean all
yum update

Install Sendmail and Spamassassin packages and its dependencies:

yum install sendmail sendmail-cf spamassassin spamass-milter
yum install perl-Mail-SPF perl-Mail-DKIM perl-Razor-Agent pyzor poppler-utils re2c
chkconfig spamassassin on
chkconfig spamass-milter on
service spamassassin start
service spamass-milter start
cd /etc/mail/
vi sendmail.mc

Add the following lines:

dnl #
 dnl # SPAMASSASSIN dnl
 dnl **
 dnl ** enable spamassassin-milter to scan for spam using spamassassin **
 dnl **
 INPUT_MAIL_FILTER(`spamassassin', `S=unix:/var/run/spamass-milter/spamass-milter.sock, F=, T=C:15m;S:4m;R:4m;E:10m')dnl
 define(`confMILTER_MACROS_CONNECT',`t, b, j, _, {daemon_name}, {if_name}, {if_addr}')dnl
 define(`confMILTER_MACROS_HELO',`s, {tls_version}, {cipher}, {cipher_bits}, {cert_subject}, {cert_issuer}')dnl
 dnl # END LOCAL ADDITIONS
 dnl #
make all

Restart Sendmail service for the changes to take effect:

service sendmail restart

In order to make sure that Spamassassin works, execute the following command:

spamassassin -D < /usr/share/doc/spamassassin-3.3.1/sample-spam.txt 2>&1 |grep -i spf

To test your mail setup and verify that the filter is installed correctly and is detecting incoming spam, send an email to an existing email account on the server with the following line in it:

XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

The email should be marked with [SPAM], and if you check the Sendmail log file using the ‘tail -f /var/log/maillog’ command, you should notice something like:

sendmail[4736]: qAGL3ib3004736: Milter add: header: X-Spam-Status: Yes, score=999.9 required=5.0

Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install this for you. They are available 24×7 and will take care of your request immediately. You can also check our guide on How to install and integrate SpamAssassin with Postfix on a CentOS 6 VPS.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

6 thoughts on “How to install SpamAssassin on a virtual server with CentOS 6”

  1. Nice write up.
    There are a couple of missing pieces in your instructions:
    The repo file when copied and pasted from the site contains spaces at the beginning of each line and causes yum not to read the file correctly.

    Second you do not have the link to download the gpg key . you should add the following:

    wget http://mirror.sfo12.us.leaseweb.net/epel/RPM-GPG-KEY-EPEL-6

    cp RPM-GPG-KEY-EPEL-6 /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

    Reply
    • Actually you can install spamass-milter x86_64 from the EPEL repository. Can you please tell us why you were unable to install spamass-milter x86_64 and what errors did you get?

      Reply
  2. When i add this line in sendmail.mc

    dnl #
    dnl # SPAMASSASSIN dnl
    dnl **
    dnl ** enable spamassassin-milter to scan for spam using spamassassin **
    dnl **
    INPUT_MAIL_FILTER(`spamassassin’, `S=unix:/var/run/spamass-milter/spamass-milter.sock, F=, T=C:15m;S:4m;R:4m;E:10m’)dnl
    define(`confMILTER_MACROS_CONNECT’,`t, b, j, _, {daemon_name}, {if_name}, {if_addr}’)dnl
    define(`confMILTER_MACROS_HELO’,`s, {tls_version}, {cipher}, {cipher_bits}, {cert_subject}, {cert_issuer}’)dnl
    dnl # END LOCAL ADDITIONS
    dnl #

    and restart the sendmail ,It says Failed to restart. Then I check the status of sendmail and its getting error from those line which is i recently add into sendmail.mc

    Reply

Leave a Comment