Home // Postfix Guides // SpamAssassin

SpamAssassin

SPAMASSASSIN
The installation of SpamAssassin should be performed as per SpamAssassin documentation.

This guide is available for information purposes, though the information contained in this guide has been rendered obsolete.

We strongly recommend that you read through the Amavisd-New Guide and implement SpamAssassin as part of that solution.

—-

The daemon spamd should be running, and a good practice would be to verify that it is running as part of the Postfix start script. Once SpamAssassin is installed and running, you will need to perform the following:

    1. Create a user and group named spam.
    2. Create a directory /var/spam and set it as user spam’s home.
    3. Make sure that the directory is owned and writable by user spam.
    4. Create a shell script /usr/local/bin/spamfilter.sh with the following contents. Note that you should make sure that your spamc and sendmail binaries are in the right places. Modify the script if they are elsewhere.

#!/bin/sh
# spamfilter.sh
INSPECT_DIR=/var/spam
SENDMAIL=/usr/sbin/sendmail
SPAMASSASSIN=/usr/bin/spamc
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
trap “rm -f in.$$; rm -f out.$$” 0 1 2 3 15
cat | $SPAMASSASSIN -f > out.$$ #|| # { echo Message content rejected; exit $EX_UNAVAILABLE; }
$SENDMAIL “$@” < out.$$
exit $?

NOTE: On our servers, prior to migrating to the Amavisd-New solution, we used to use another re-injection listener, and a perl script to send the output of the spamfilter script back into the correct queue. This is due to the multiple steps of filtration that are used on our servers, and the problem created when messages are fed back into a the wrong queue (creating a mail loop). Please see this perl script for how to do this. If you are using an AntiVirus softwre package with Postfix, it is almost a certainty that you will have to use this perl script and modified spamfilter script.

  1. Set ownership (chown) the /usr/local/bin/spamfilter1.sh script to user spam.
  2. If you are not already using a content_filter, add the following to main.cf:
    content_filter=spamfilter:
  3. If you are already using a content filter, add the following to the re-injection listener in master.cf, and be careful that you don’t inadvertently create a mail loop on the re-injection portion of the spamfilter script:
    -o content_filter=spamfilter:
  4. Add the following to master.cf (all on one line):
    spamfilter unix – n n – – pipe flags=Rq user=spam argv=/usr/local/bin/spamfilter.sh ${sender} ${recipient}
  5. Start up the spamd daemon, and add it to the list of processes that come up with the system.NOTE: Make sure you start up SpamAssassin spamd properly. On our servers we use the following parameters for spamd when started in rc scripts:
-d Runs the program in daemon mode
-r /var/run/spamd.pid Sets the pid file
-a Use auto-whitelists
-u spam Run as user spamfilter
-x Disable user config files (since we run global)
-H /var/spam Specify home directory

Upon installing SpamAssassin, you will also have a file named local.cf placed in /etc/mail/spamassassin (or elsewhere depening on your installation). This file will contain additional details about how you want your system to run. Please see the SpamAssassin Conf documentation for more information about the local.cf file and other configurations. We strongly recomend that you enable auto-whitelist and bayes. Installing Razor2 would also be very beneficial.

Leave a Reply

Your email address will not be published. Required fields are marked *