Using SpamAssassin with postfix

It took me many hours to get SpamAssassin to work with postfix. It should not have been so hard. I hope this page can help somebody else.

I was working on a Debian stable (woody) machine. This may work for other configs too. SpamAssassin is one of the few packages that should be more up2date than stable. The newer version is MUCH easier to use, and automagicly includes many of the features we all want (like Bayesian filtering). I got 3.0 from Add the line:

     deb woody spamassassin
to /etc/apt/sources.list and then
apt-get install spamassassin
. to get the latest spamassassin on Debian stable.

This document assumes you already have postfix running.

  1. create a user and group called mailfilt which has no password, and cannot log in. (su from root only)
  2. edit /etc/postfix/ as follows:
    Change the line:
    smtp    inet  n       -       -       -       -       smtpd
    smtp    inet  n       -       n       -       -       smtpd -o content_filter=spamassassin:
    and add the line:
    spamassassin unix - n n - - pipe flags=Rq user=mailfilt argv=/usr/local/bin/ -f ${sender} ${recipient}
    to the end of the file.
  3. Create a file like:
    -rwxr-xr--    1 mailfilt mailfilt       71 Oct 25 11:27 /usr/local/bin/
    with the contents
    /usr/bin/spamc | /usr/sbin/sendmail -i "$@"
    exit $?
  4. Make sure that spamd is running:
    /etc/init.d/spamassassin restart
  5. Re-initialize postfix to start using the spamfilter client:
    /etc/init.d/postfix reload
You should now have extra spam headers (and subject line changes) in your e-mails on the system.

I think that the default SpamAssassin config will do this, but I'm not totally sure. If you don't like the results, look for info on editing the /usr/share/spamassassin/ file.

Aaron Birenboim
Last modified: Thu Feb 9 17:13:41 MST 2006