SpamAssassin installation manual

Authors: Ferruca <fernando@nediam.com.mx> and Nediam <javier@nediam.com.mx>
Publication date: 2006-10-20
Last updated: 2007-06-14


This manual is designed to install SpamAssassin working with qmail and qmail-scanner. The operating system we used for testing was Debian GNU/Linux.

*** NOTE: To integrate SpamAssassin with Postfix, check this excellent documentation: http://wiki.apache.org/spamassassin/IntegratedSpamdInPostfix.

  1. Previous considerations. Just like qmail-scanner, SpamAssassin works with Perl, thus is necessary to have installed Perl as well as the following modules/packages:
    - Digest::SHA1
    - Digest::HMAC
    - Net::DNS
    - Time::HiRes
    - HTML::Tagset
    - HTML::Parser
    - Pod::Usage
    - Parse::Syslog
    - Interpreters::Storable
    - Statistics::Distributions
    - perl-suid

    Note: In the distribution that we used (Debian GNU/Linux), the above packages can be installed of the following way:
    apt-get install libdigest-sha1-perl
    apt-get install libdigest-hmac-perl
    apt-get install libnet-dns-perl
    apt-get install libtime-hires-perl
    apt-get install libhtml-parser-perl
    apt-get install libparse-syslog-perl
    apt-get install libstorable-perl
    apt-get install perl-suid



  2. Download the sources from the official SpamAssassin site http://spamassassin.apache.org/ At the time of this writing, the most recent version of SpamAssassin is 3.1.7. Supposing the *.tar.bz2 file was downloaded to /usr/local/, extract it and decompress it:
    SERVER:~# cd /usr/local
    SERVER:/usr/local# bzcat Mail-SpamAssassin-3.1.7.tar.bz2 | tar -xvf -
    SERVER:/usr/local# cd Mail-SpamAssassin-3.1.7


  3. Create the Makefile, do the compilation and copy the executables to the right locations::
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# PERL Makefile.PL
    Note: The program will ask the administrator's email.
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# make
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# make install


  4. Create the user and group under which the SpamAssassin daemon will run:
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# groupadd spamd
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# useradd -g spamd -s /bin/false -m -d /home/spamassassin spamd


  5. Modify the file /etc/mail/spamassassin/local.cf so it contains only the following lines:
    # Set the threshold at which a message is considered spam (default: 5.0)
    required_score	5.0
    # Add the text *** I AM SPAM *** to the Subject header of spam e-mails
    rewrite_header subject *** I AM SPAM ***
    # Enable bayesian classifier
    use_bayes	1
    # Bayesian classifier auto-learning
    bayes_auto_learn	1
    

  6. Create a directory under /var/run/ where SpamAssassin daemon process id will be located and then change the ownership to spamd:
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# mkdir /var/run/spamd
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# chown -R spamd:spamd /var/run/spamd


  7. Create the init script called /etc/init.d/spamd with the following lines (script obtained from the qmailrocks site: http://www.qmailrocks.org/downloads/scripts/misc/debian_spamd):
    #! /bin/sh
    
    #Spamd init script for Debian (woody)
    #Tweaked for the qmailrocks.org qmail installation guide on 1-6-2005
    
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
    DAEMON=/usr/sbin/spamd
    NAME=spamd
    SNAME=spamd
    DESC="SpamAssassin Mail Filter Daemon"
    PIDFILE="/var/run/spamd/$NAME.pid"
    PNAME="spamd"
    DOPTIONS="-x -u spamd -H /home/spamd -d --pidfile=$PIDFILE"
    
    # Defaults - don't touch, edit /etc/mail/SpamAssassin/local.cf
    ENABLED=0
    OPTIONS=""
    
    #test -f /etc/mail/SpamAssassin/local.cf && . /etc/mail/SpamAssassin/local.cf
    
    #test "$ENABLED" != "0" || exit 0
    
    test -f $DAEMON || exit 0
    
    set -e
    
    case "$1" in
      start)
            echo -n "Starting $DESC: "
            start-stop-daemon --start --pidfile $PIDFILE --name $PNAME \
                --startas $DAEMON -- $OPTIONS $DOPTIONS
    
            echo "$NAME."
            ;;
      stop)
            echo -n "Stopping $DESC: "
    
            start-stop-daemon --stop --pidfile $PIDFILE --name $PNAME
    
            echo "$NAME."
            ;;
      restart|force-reload)
            echo -n "Restarting $DESC: "
            start-stop-daemon --stop --pidfile $PIDFILE --name $PNAME --retry 5
            start-stop-daemon --start --pidfile $PIDFILE --name $PNAME \
                --startas $DAEMON -- $OPTIONS $DOPTIONS
    
            echo "$NAME."
            ;;
      *)
            N=/etc/init.d/$SNAME
            echo "Usage: $N {start|stop|restart|force-reload}" >&2
            exit 1
            ;;
    esac
    
    exit0
    


  8. Update the init scripts (we did it with update-rc.d because we are using Debian) and start the SpamAssassin daemon (spamd):
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# update-rc.d spamd start 75 2 3 4 5 .
    SERVER:/usr/local/Mail-SpamAssassin-3.1.7# /etc/init.d/spamd start


    QMAIL-SCANNER INSTALLATION
  9. Qmail-Scanner will be the interface between Qmail and SpamAssassin. Qmail-Scanner will analyze, using SpamAssassin, all the incoming emails that arrive to the qmail queue. First we have to create the user and group under which Qmail-Scanner will run: SERVER:~# groupadd qscand
    SERVER:~# useradd -c "Qmail-Scanner Account" -g qscand -s /bin/false qscand

    Qmail-Scanner also needs the Maildrop program to work, so we download it from: http://www.courier-mta.org/maildrop/. At the time of this writing, the most recent version of maildrop is 1.05. Supposing the package was downloaded to /usr/local/, extract it and decompress it:
    SERVER:~# cd /usr/local
    SERVER:/usr/local# bzcat maildrop-2.0.2.tar.bz2 | tar -xvf -
    SERVER:/usr/local# cd maildrop-2.0.2

    Then install it normally:
    SERVER:/usr/local/maildrop-2.0.2# ./configure
    SERVER:/usr/local/maildrop-2.0.2# make
    SERVER:/usr/local/maildrop-2.0.2# make install


  10. Now we're ready to install Qmail-Scanner. We download it from: http://qmail-scanner.sourceforge.net/. At the time of this writing, the most recent version of Qmail-Scanner is 2.01. Supposing the package was downloaded to /usr/local/, extract it and decompress it:
    SERVER:~# cd /usr/local
    SERVER:/usr/local# tar -zxvf qmail-scanner-2.01.tgz
    SERVER:/usr/local# cd qmail-scanner-2.01

    Then install it normally:
    SERVER:/usr/local/qmail-scanner-2.01# ./configure
    SERVER:/usr/local/qmail-scanner-2.01# ./configure --install
    Note: You have to answer correctly all the questions during the installation.

    After the installation, a script called qmail-scanner-queue.pl should have been created in /var/qmail/bin/.

  11. Let's verify that Qmail-Scanner installation was successful by executing the qmail-scanner-queue script:
    SERVER:/var/qmail/bin# setuidgid qmaild /var/qmail/bin/qmail-scanner-queue.pl -g
    The output should look similar to this:
    perlscanner: generate new DB file from /var/spool/qscan/quarantine-events.txt
    perlscanner: total of 12 entries.
    


    CONNECTING QMAIL-SCANNER WITH QMAIL
  12. Qmail-Scanner works the following way: it cath all the incoming mails that arrive to the qmail queue, analyze them with SpamAssassin, change some things in the headers if required (like the subject to tag the mail as spam) and then return them to the qmail queue. To interconnect Qmail-Scanner with qmail, we have to add the following line to /etc/tcp.smtp so qmail executes the qmail-scanner-queue.pl whenever a mail arrives to the queue:
    :allow,QMAILQUEUE="/var/qmail/bin/qmail-scanner-queue.pl"


  13. Now edit the file /var/qmail/bin/qmail-scanner-queue.pl, search for the line $spamc_subject='' and add the text you like to identify spam:
    my $spamc_subject='*** I AM SPAM ***'

  14. Finally, recreate the SMTP cdb database and restart qmail
    SERVER:~# qmailctl cdb
    SERVER:~# qmailctl restart


If everything is working correctly, every email that arrives to our mail server and that be catalogued as spam will have the text: *** I AM SPAM *** before the subject.


References:


The latest version of this document is available at: http://nediam.com.mx/en/docs/spamassassin_manual/index.php

<< 0 comments >>



TOP