SpamAssassin is commonly used to identify spam, so that it can be given the proper handling by a mail delivery agent such as procmail or directly by the MTA as in the case of a sendmail message filter (milter).
The easiest way to install SpamAssassin is via CPAN. As root, do the following:
perl -MCPAN -e shell install Mail::SpamAssassin quit
If you wish to install it from the distro, begin with the latest source which can be found at: http://spamassassin.apache.org/. Once you have downloaded the source tarball, unzip it in the top level directory where you wish the source/build tree to reside:
tar -xvzf Mail-SpamAssassin-m.n.xx.tar.gz
In the INSTALL file, you can check the list of prerequisites that should be installed (mostly from CPAN) before SpamAssassin can be installed. First off, make sure that you have a version of the Perl Interpreter that is at least 5.8.2 (some of the prerequisite CPAN modules will not build with 5.8.0). Some of the SpamAssassin install notes that mention 5.6.1 are just plain wrong. Ignore them and get a version of Perl later than or equal to 5.8.2. It is known to work on 5.8.8, for example.
Sadly enough, you are on your own when it comes to checking whether you have all the CPAN modules installed or not. The dipsticks who wrote CPAN didn't think to include a check-if-installed command so, short of just installing the module and seeing what happens, you're pretty much on your own. The CPAN FAQ has some notes on how to go about finding out but they're less than satisfying.
If, somehow, you find any of the required modules missing or any of the optional modules that enable features that you may want to use, get them from CPAN and install them. Presuming you have an Internet connection that will allow CPAN to work, do:
su perl -MCPAN -e shell install ... quit
Switch to the source tree where you extracted the SpamAssassin source and build the makefile that is used to build SpamAssassin. Once you've done that, run it to do the actual build:
cd Mail-SpamAssassin-m.n.xx perl Makefile.PL PREFIX=/usr make su make install
/etc/rc.d/init.d/spamassassin:
This startup script will start SpamAssassin's spamd daemon so that requests to identify spam may be passed to it without incurring the overhead of starting up the Perl interpreter each time a message is to be identified.
#!/bin/sh # # spamassassin - This script starts and stops the spamd daemon # # Revision History: # ewilde 2012Jun09 Add pid file. # ewilde 2009Jan18 Update to start/stop before/after sendmail. # # chkconfig: 2345 79 31 # description: Spamd is a daemon process which uses SpamAssassin to check \ # email messages for SPAM. It is normally called by spamc \ # from a MDA. # # processname: spamd # pidfile: /var/run/spamd.pid # config: /etc/mail/spamassassin/local.cf (among others) # # # Define the install path for the SpamAssassin binaries, etc. Define the # program to run. # INSTALL_PATH="/usr/bin" SPAM_DAEMON="spamd" # # Load the function library. # if [ -f /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions fi # # Source the networking configuration. # if [ -f /etc/sysconfig/network ]; then . /etc/sysconfig/network else NETWORKING=no fi # # Source the spamd configuration or take the defaults. # if [ -f /etc/sysconfig/spamd ] ; then . /etc/sysconfig/spamd else SPAMD_PORT=783 SPAMD_OPTIONS="-c -d -L" SPAMD_PID=/var/run/spamd.pid fi [ -z "$SPAMD_PORT" ] && SPAMD_PORT=783 [ -z "$SPAMD_PID" ] && SPAMD_PID=/var/run/spamd.pid # # Check that networking is up. We talk to our customers using TCP/IP. # [ "x$NETWORKING" != xyes ] && exit 0 # # Big kludge-oh-mundo. Spamd runs out of PATH. Also, make sure we have # something to run. # [ -f $INSTALL_PATH/$SPAM_DAEMON ] || exit 0 PATH=$PATH:$INSTALL_PATH # # Upon startup, start the daemon. # start() { echo -n "Starting $SPAM_DAEMON: " daemon $SPAM_DAEMON $SPAMD_OPTIONS -p $SPAMD_PORT -r $SPAMD_PID RETVAL=$? echo # # If startup succeeded, lock the lockfile. # [ $RETVAL = 0 ] && touch /var/lock/subsys/spamd } # # Upon shutdown, stop the daemon. # stop() { echo -n "Shutting down $SPAM_DAEMON: " killproc $SPAM_DAEMON RETVAL=$? echo # # If shutdown succeeded, unlock the lockfile. # if [ $RETVAL = 0 ]; then rm -f /var/lock/subsys/spamd rm -f $SPAMD_PID fi } # # See how we were called. # case "$1" in # # Start. # start) start ;; # # Stop. # stop) stop ;; # # Restart or reload (whatever). # restart|reload) stop sleep 3 start ;; # # Conditional restart. # condrestart) if [ -f /var/lock/subsys/spamd ]; then stop start fi ;; # # Give the status of spamd. # status) status $SPAM_DAEMON ;; # # Help text. # *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" exit 1 esac exit 0
Don't forget to install the startup script using chkconfig:
/sbin/chkconfig --add spamassassin /sbin/chkconfig spamassassin on
/etc/sysconfig/spamd:
If you are planning to use spamd with the sendmailfilter, you should create this file, since doing so will cause the sendmail startup script to invoke spamd for email filtering. The options for the spamassassin startup script (above) are also included in this file.
The permissions on this file should be:
-rw-r--r-- 1 root root
Here is a sample of the complete file:
# # Configuration for the SpamAssassin daemon. # SPAMD_PORT=2527 SPAMD_OPTIONS="-c -d -L"
Note that RPM installations of SpamAssassin install a "spamassassin" file in /etc/sysconfig that does what the "spamd" file, above, does. If you wish to use a file with that name, change "spamd" to "spamassassin" in the /etc/init.d/spamassassin, and possibly the /etc/init.d/sendmail startup scripts herein.
The last step, for later versions of SpamAssassin (e.g. 3.3.2), is to run the sa-update command as root:
su sa-update
You will know if you forgot to do this, if you receive the really informative error message, upon running "/etc/init.d/spamassassin start" that reads:
child process [18755] exited or timed out without signaling production of a PID file