Swarthmore College Department of Computer Science

setting up spamassassin

Adapted from The SpamAssassin Wiki

Spamassassin is a program that can scan a mail message and add headers that tell someone or something reading the headers if the message is likely spam. Combined with Procmail, we can have it look at messages and if they are likely spam move them into a spam folder.

If you just want to enable Spamassassin on your account you should run:

spam-filter enable

That will walk you through the process doing most of it. Otherwise I recommend you go through the steps here, as you will learn more.

Normally when your mail comes into the server it just sits in your inbox waiting for you. But if you have a file named .forward in your home directory, then what happens to your mail depends on the contents of that file. In this case, we want all mail to be piped through Procmail. So we set our .forward file:

allspice[~]% echo '"|/usr/local/bin/procmail"' > .forward

Now, make a .procmailrc file in your home directory containing the below lines, which are modified from the SpamAssassin Wiki's procmailrc.example.

# SpamAssassin sample procmailrc
#
# Pipe the mail through spamassassin 
#
# The condition line ensures that only messages smaller than 250 kB
# (250 * 1024 = 256000 bytes) are processed by SpamAssassin. Most spam
# isn't bigger than a few k and working with big messages can bring
# SpamAssassin to its knees.
#
# The lock file ensures that only 1 spamassassin invocation happens
# at 1 time, to keep the load down.
#
:0fw: spamassassin.lock
* < 256000
| spamc

# Optional: 
#  All mail tagged as spam (eg. with a score higher than the set threshold)
#  got a "X-Spam-Status: Yes" header from spamassassin.  Now we tell
#  procmail that any messages with this header are to be moved to the 
#  folder "probably-spam"
:0:
* ^X-Spam-Status: Yes
mail/probably-spam
#
# The alternative is to leave the prior three lines out and have your 
# mail client filter on the "X-Spam-Status" header.

And finally create the "probably-spam" mailbox:

allspice[~]% touch mail/probably-spam

Now any new mail messages you receive will be told by the .forward file to go through Procmail which is told by the .procmailrc to go through Spamassassin. All mails that Spamassassin decides are spam will get put into the "probably-spam" folder in your mail folder. You should check this folder from time to time and especially in the beginning to make sure that wanted mail is not getting put into your spam folder.

If you are using mutt, pine or some other local mailreader, you should have no problems with your "probably-spam" folder. If you are using an IMAP client (like Thunderbird), however, you will need to have your mail client subscribe the "probably-spam" folder. In Thunderbird, right-click the account's name in the lefthand panel which lists the mailboxes and choose "Subscribe...". put a check mark next to the "probably-spam" line and click "ok".

Now send yourself two messages, one normal, and one containing the following line:

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

Wait about five minutes and make sure that the normal one goes through to your inbox and the second one goes to your spam folder. If they do, then you've set up Spamassassin properly.

If you are curious about how Spamassassin works or have questions, look at the Spamassassin wiki or ask your sysadmins. If you are curious about what you can do with procmail, see our procmail guide.