You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 22 Next »

How do I use SpamAssassin with procmail?

First you must ensure that procmail is used as your local mail delivery agent (MDA). To enable this as a per-user setting, add a .forward or .qmail file in your home directory containing the below line

|formail -ds /usr/bin/procmail

Upon each incoming message, formail is used to format the mail message in a format that is appropriate for mbox mailboxes (you may not need this), and then procmail is used to further process the message.

Now, edit or create a .procmailrc file in your home directory containing the below lines. If you already have a .procmailrc file, add the lines to your .procmailrc file:

:0fw:spamassassin.lock
* < 256000
| spamassassin

:0e
{
  EXITCODE=$?
}

:0:
* ^X-Spam-Flag: Yes
caughtspam

The first stanza filters all incoming mail through SpamAssassin and tags probable spam with a unique header. This rule will use a lock file (spamassassin.lock); this is a good idea if there will be more than one instance of SpamAssassin working on a message. The next stanza protects against errors. If spamassassin returns an error, it is passed back to the mail transfer agent; this improves robustness of mail delivery.

Most people prefer to have spam blocked and saved to a file in their mail directory. The next stanza instructs procmail to save any tagged messages to a "caughtspam" folder in your procmail MAILDIR directory.

For a more complicated example see the procmailrc.example file in the distribution:

http://spamassassin.org/dist/procmailrc.example

The spamc client program can be used instead of spamassassin, if you intend to install and use the spamd server system-wide.

Read 'man procmailrc' and 'man procmailex' for futher details and explanation.

  • No labels