Configuring Procmail for SpamAssasin

Written by M. W. Chang on 24-June-02.
Date: 16 July, 2002

I would assumed you or your distribution installed procmail and sendmail properly.

Fire up Perl's CPAN shell as per the README file in doc dinstall Mail::SpamAssassin

# perl -MCPAN -e shell
cpan> o conf prerequisites_policy ask
cpan> install Mail::SpamAssassin
cpan> quit


You may need to update your perl first. Just follow the instructions and answer the questions with default answer (press ENTER).

If everything went well, you should able to fire up SpamAssassin.  Let's check it's online help:
# spamassassin -h
# man spamassassin


By default (for my Caldera Openlinux 3.1), the config file for SpamAssassin is /etc/mail/spamassassin/local.cf. But you can always overide this with

# spamassassin -a /path/to/local.cf

How does SpamAssassin work? When it was passed a message from the stdin, it would make a call to a remote site which contains a list called Realtime Black List (DNSBL) with the sender's email address in the message. If the
sender's email address was in the DNSBL, it would add a RFC822 modifier to the message "X-Spam-Status:" and set it to "Yes".

Now that the spamming messages was tagged, you can use procmail or whatever mail processor to remove it easily.

create /etc/procmailrc:

# you need a file ~/.forward with the following line:
# "|exec /usr/bin/procmail"
# user-specific procmailrc is ~/.procmailrc
#
# to run procmail for all users
# 1. create /etc/procmailrc
# 2. touch /var/log/procmail
# 3. chmod 666 /var/log/procmail
# 4. make sure that /var/log/junkmail is created
#
# references:
# http://www.pegasus.rutgers.edu/~elflord/unix/procmail.html
# the link features a simplified how-to of Nanay, plus a link
# to grep tutorial
#
# Next may be needed if you invoke programs from your procmailrc
# Details in Check Your $SHELL and $PATH in Troubleshooting below
#
PATH="/usr/local/bin:/usr/bin:/usr/local/sbin:/bin:/sbin:/usr/sbin"
SHELL=/bin/sh

# Directory for storing procmail configuration and log files
# You can name the environment variable MDIR anything you like
# or, if you prefer, don't set it (but then don't refer to it!)
PMDIR=/tmp

# Put ## before LOGFILE if you want no logging (not recommended)
LOGFILE=/var/log/procmail
LOCKFILE=/tmp/procmail

# To insert a blank line between each message's log entry,
# uncomment next two lines (this is helpful for debugging)
LOG="
"

# Set to yes when debugging
VERBOSE=no
# Remove ## when debugging; set to no if you want minimal logging
## LOGABSTRACT=all

JUNKMAIL=/var/mail/nobody
NULL=/dev/null

# simplest rule for testing
:0
* ^Subject:.*test
{
LOG="test: "
:0
$JUNKMAIL
}

# if you want to use your own conf file
# -c /etc/mail/spamassassin/local.cf
:0fw
| /usr/bin/spamassassin -P
:0
* ^X-Spam-Status: Yes
$JUNKMAIL
# all un-touched mail to go back to the user's own mbox by default

searchSearch Index