Jump to content

How to install and setup in SpamAssassin.

Recommended Posts


SpamAssassin is a computer program used for e-mail spam filtering. SpamAssassin uses a variety of spam-detection techniques, including DNS-based and fuzzy-checksum-based spam detection, Bayesian filtering, external programs, blacklists, and online databases. It will save your mailbox from many unwanted spam emails.

For this tutorial we are using Ubuntu 16.04 distribution, however, you should be able to use it for all Debian and Ubuntu distributions we offer on Time4VPS.

Update System

First things first. Like always, first of all, we recommend updating your server. It can be done by simply executing:

apt-get update


After our server is up to date we can start the installation. Use apt-get to install Spamassassin and spamc:

apt-get install spamassassin spamc -y

While installing you can get a message about the kernel, we are using stable kernel version 2.6.32 for OpenVZ, so you do not need to worry about that, just click OK.

Adding User

There are a few steps that has to be taken to make it fully functional. To run SpamAssassin you need to create a new user on your VPS. First, add the group spamd:

groupadd spamd

Then add the user spamd with the home directory /var/log/spamassassin:

useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd

Then create the directory /var/log/spamassassin:

mkdir /var/log/spamassassin

And change the ownership of the directory to spamd:

chown spamd:spamd /var/log/spamassassin

Setting Up

Open the SpamAssassin config file:

nano /etc/default/spamassassin

Note: If you do not have nano installed on your server, you can do it simply with the command:

apt-get install nano

To enable Spamassassin and automatic rule updates in order to get the latest spam filtering rules to find the CRON and ENABLED variables and change then to:


Now create a variable named SAHOME with the Spamassassin home directory:


Find and change the OPTIONS variable to:

OPTIONS="--create-prefs --max-children 2 --username spamd \
-H ${SAHOME} -s ${SAHOME}spamd.log"

After setting up is complete we can start the Spamassassin daemon by using the following code:

service spamassassin start

Configuring Postfix
SpamAssassin is set up, however, emails are still not going through it. To enabling that, open Postfix config file:

nano /etc/postfix/master.cf

Find the line:

smtp inet n - - - - smtpd

And add the following to the end of the line:

-o content_filter=spamassassin

Now, Postfix will pipe the mail through SpamAssassin.

To setup after-queue content filter add the following line to the end of the file

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:

service postfix restart


To get the maximum use of SpamAssassin you have to create rules. Open the SpamAssassin default rules file using:

nano /etc/spamassassin/local.cf

To activate a rules uncomment line by removing the # symbol in the beginning of the line. Some line we recommend to uncomment:

rewrite_header Subject *****SPAM***** - To add a spam header to spam mail.

required_score 5.0 - Spamassassin gives a score to each mail after running different tests on it. This line marks the mail as spam if the score is more than the value specified in the rule.

use_bayes 1 - To use Bayes theorem to check mails.

bayes_auto_learn 1 - To enable Bayes auto-learning.

After adding the above details, save the file and restart spam assassin.

service spamassassin restart


To see if SpamAssassin is working, you can check the SpamAssassin log file using:

nano /var/log/spamassassin/spamd.log

or send the email from an external server and check the mail headers.


Using SpamAssassin, it is very easy to protect your mailbox from spammers. The best thing about SpamAssassin is that we can create rules by ourselves and manage it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...