Advanced SpamAssassin/Procmail Setup

There's a great deal of flexibility in how SpamAssassin and Procmail are used. In order to best understand your options, you must understand a little of how these programs work.

  1. postfix looks for ~/.forward

    When delivering mail, the mail server (postfix) checks to see if you have a file called .forward in your home directory. If you have one, it gets its delivery instructions from there (more on that later). If you don't, it runs your mail through procmail.

  2. postfix starts procmail

    In the absence of a .forward file, postfix runs procmail with no options (this is important). When procmail is run with no options, it first looks for commands in the file /etc/procmailrc and then in ~/.procmailrc.

  3. procmail runs /etc/procmailrc

    First, procmail runs the mail through the commands in /etc/procmailrc. Here, this file contains the following commands:

    :0fw
    | /usr/bin/spamc
    
    This "filters" the mail throught SA. The mail is sent in and comes modified to reflect the results of the scan. This probably just means that a few headers are added.

  4. procmail runs ~/.procmailrc

    If it exists, procmail continues to process the mail through your personal procmail config file, .procmailrc. You can put commands here to direct mail flagged as spam to a special mailbox that you check only occasionally. (DO NOT have mail automatically deleted. SpamAssassin DOES make mistakes.)

Editing your .forward file

Most of the crazy configuration you can do comes from editing your .forward file. If you have a .forward file, postfix will deliver mail according to its contents rather than the default procmail method. Here are a few things you can put in your .forward:

Editing your SpamAssassin config

Most configuration of SpamAssassin happens in the ~/.spamassassin/user_prefs file. As it says near the top of that file, you can see what options are available by running man Mail::SpamAssassin::Conf at a command prompt.

Editing your procmail config

You can do a lot with procmail. For help editing your .procmailrc, run man procmailrc at a command prompt. Here's a simple .procmailrc that dumps tagged messages into a spam folder.
MAILDIR=$HOME/mail
LOGFILE=$HOME/mail/log

:0:
* ^X-Spam-Status: Yes
spam