This is a very barebones setup for Postfix / SpamAssassin / Procmail. It is not performance optimized (in testing it handled about 25 mails per minute on an Athlon 900) look into spamc/spamd if you have higher volume.

This all assumes the following rig:
Debian Woody, fairly minimal installation.
Postfix installed and functional.
Pine and UW-IMAPD as the clients.

If your rig differs from the list above, so will your installation. This is just what worked for me.

Step 1:
This is important: You have to start with a fully functional install of Postfix. If it's not working right before you start, it will still not be working right when you're done, and it will be doing more things. That will make it a lot harder to fix.

Step 2:
Read all the way through this. It's not long, and it will prepare you for what's ahead.

Step 3:
Accept all responsibility for your actions. It is my deep and heartfelt belief that if you do what I've listed here it will destroy your computer, cause your refrigerator to defrost while you're on vacation, and make your girlfriend leave you. None of that happened to me, but if you choose to proceed, anything that happens is your responsibility.

Download the latest version of SpamAssassin
For most software, I use Debian's apt utilities to keep up to date. But with the rapid pace of development of spam, having the latest weapons is worthwhile.

Install Perl HTML::Parser
# apt-get install libhtml-parser-perl

Make SpamAssassin
$ tar -xvzf Mail-SpamAssassin-2.60.tar.gz
$ cd Mail-SpamAssassin-2.60
$ perl Makefile.PL
$ make
$ su
# make install

Create the filter user
Do this however you like. Filter should have a * password, tmp as a home directory, and a valid shell. As root, you will want to su filter for testing, but filter should not be able to log in.

Make sure procmail is installed
$ which procmail

Configure SpamAssassin /etc/mail/spamassassin/
required_hits 8
add_header all Level _STARS(X)_
rewrite_subject 1
subject_tag Spam [_HITS_]

Create /usr/local/bin/
/usr/local/bin/spamassassin | /usr/sbin/sendmail -i "$@"
exit $?

Set the access rights for sa-filter
# chown filter:filter /usr/local/bin/sa-filter
# chmod u+x /usr/local/bin/sa-filter
# chmod go-x /usr/local/bin/sa-filter

Test sa-filter
# su filter
$ cat spam.txt | sa-filter -f bob -- bob
$ cat notspam.txt | sa-filter -f bob -- bob

The previous test should leave you with both emails in your inbox, and the spam one should be marked spam. If not, don't move on until it works right. As things stand right now, postfix is still working exactly as it was before - no harm done.

That's it for su'ing to filter. Set filter's home directory to something nonexistent and shell to /bin/false now.

Abandon Hope All Ye Who Enter
Remember the part about your computer, refrigerator, and relationship all crashing? This is where it all happens. Remember, it's not my fault.

Make a backup copy of /etc/postfix/
# cp /etc/postfix/ /etc/postfix/

Make a backup copy of /etc/postfix/
# cp /etc/postfix/ /etc/postfix/

Edit /etc/postfix/
Add the filter
# Spam Filter
spamassassin unix - n n - - pipe
  user=filter argv=/usr/local/bin/sa-filter -f ${sender} -- ${recipient}
Change the settings for smtp and smtpd:
smtp inet n - n - - smtpd
  -o content_filter=spamassassin:
smtp unix - - n - - smtp
  -o content_filter=spamassassin:

Add Procmail to /etc/postfix/
mailbox_command = /usr/bin/procmail -f- -a "$USER"

Bounce Postfix
# /etc/init.d/postfix reload

Test Mailing (from a different machine):
$ cat spam.txt | /usr/sbin/sendmail
$ cat notspam.txt | /usr/sbin/sendmail

This test should do the same as before, you should get both mails in your inbox, and the spam one should be marked as spam.

If this is not what happened, restore the postfix configuration and

Set up procmail

Create the .procmail directory
$ cd ~
$ mkdir .procmail

Create ~/.procmailrc
# VERBOSE=yes # turn this on for debugging
MAILDIR=$HOME/mail # this is for pine - yours may differ
# If none of the filters match, it will go to your inbox.

Create ~/.procmail/rc.spam
* ^X-Spam-Level: XXXXXXXX

Test Mailing (from a different machine):
$ cat spam.txt | /usr/sbin/sendmail
$ cat notspam.txt | /usr/sbin/sendmail

This time, the non-spam should show up in your inbox, and the spam should go to the folder zSpam.

If this is not what happened, restore the postfix configuration and

And you're done.

Copyright 2003 by Robert Bushman.
Creative Commons License
This work is licensed under a Creative Commons License.