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

Compare with Current View Page History

« Previous Version 31 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, you may need to add a .forward or .qmail file in your home directory containing the following line (Note: the quotes matter)

"| 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. Note that many (most???) Unix account configurations already forward through procmail by default, and so no change may be necessary.

Now, edit or create a .procmailrc file in your home directory containing the below lines, which come from the [http://spamassassin.org/dist/procmailrc.example procmailrc.example].

# SpamAssassin sample procmailrc
#
# Pipe the mail through spamassassin (replace 'spamassassin' with 'spamc'
# if you use the spamc/spamd combination)
#
# 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
| spamassassin

# Mails with a score of 15 or higher are almost certainly spam (with 0.05%
# false positives according to rules/STATISTICS.txt). Let's put them in a
# different mbox. (This one is optional.)
:0:
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
almost-certainly-spam

# All mail tagged as spam (eg. with a score higher than the set threshold)
# is moved to "probably-spam".
:0:
* ^X-Spam-Status: Yes
probably-spam

# Work around procmail bug: any output on stderr will cause the "F" in "From"
# to be dropped.  This will re-add it.
:0
* ^^rom[ ]
{
  LOG="*** Dropped F off From_ header! Fixing up. "
  
  :0 fhw
  | sed -e '1s/^/F/'
}

If you already have a .procmailrc file, add the above lines to your .procmailrc file. If you don't currently have a procmail file, you can import that one by entering

wget http://spamassassin.org/dist/procmailrc.example
mv procmail.example .procmailrc

Another common (but more complicated) use of procmail is to forward mail to another account, after processing with SpamAssassin. This can also support mistake-based Bayes training. See ProcmailToForwardMail.

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