Integrated Spamassassin and Postfix MTA Setup on Ubuntu


The wiki entry on the Spamassassin wiki for the simple setup with Postfix is almost there. I recently setup my 12.04 Ubuntu server with Spamassassin with Postfix and everything is working well. I had to do a few more steps to get it working. Here is what I did.

1. Create the script detailed on the wiki. Place it in /usr/bin/ and chmod +x it. Ensure the newly-created /usr/bin/ has correct permissions (0755), and is owned by root:root.

2. Install/confirm spamassassin is there on Ubuntu

3. Create a new user in Ubuntu “spamd” and create a home directory for it. This is where Spamassassin is going to want to put the Bayes information. It will store it in /home/spamd/.spamassassin

4. Change the /etc/postfix/ first smtp line to this

and add the spamfilter entry towards the bottom of the same /etc/postfix/ file

Here is what mine looks like –


5. Start spamd. I just started it with a

6. Restart postfix and send a few emails in and out of the server to make sure you have a working system. You should see verbose scoring in headers or, if you get spam during this time, some verbose scoring totals in the email body like below.


7. If things are working, you can now go in a tweak some stuff. The files you might want to mess with right off the bat are the spamassassin files in /usr/share/spamassassin


8. I edited the contact address and you can also change the flag on what you want your threshold to be and if you want to have SA insert the scoring in the body of the message as it does by default. These options are in:

and change “report_contact” to your email address


and there are more options detailed over at the Spamassassin wiki >>

Spamassassin and Postfix working together have been great. This is a simple setup with just a few components to minimize possible configuration issues or points of failure. Hope this helps.


Leave a comment or reply

  • Thanks for this post how ever think there’s a typo in the last code:

    unix – n n – – pipe
    flags=Rq user=spamd argv=/usr/bin/ -oi -f ${sender} {recipient}

    Your missing a $ on the {recipient}

    so should read

    unix – n n – – pipe
    flags=Rq user=spamd argv=/usr/bin/ -oi -f ${sender} {recipient}

    Corrected this then it worked fine

    Hope this helps


  • Thanks for this… really helped. I’ve looked at SpamAssassin several times in the past and always given up.

    This is all working fine, but need to go one step further… what is the best way to take this and have mail marked as spam delivered to a spam folder on the server rather than to the recipient?