Installing SpamAssassin

SpamAssassin is a mail filter which attempts to identify spam using text analysis and several internet-based realtime blacklists.

Additional drop-in rule sets are available at
http://wiki.apache.org/spamassassin/CustomRulesets

The official SpamAssassin website is at http://spamassassin.apache.org/

When we install SpamAssassin from ports, it installs all the required Perl Modules for us which makes installing SpamAssassin really, Really easy! Start be doing the following:


# cd /usr/ports/mail/p5-Mail-SpamAssassin
# make install

When you run this, You will get a pop-up box asking to enable a few things. Lets just make sure the settings below are checked. To check the setting, Just hit the spacebar when the cursor is over the selected option:

AS ROOT
SPAMC
GNUPG

 We will now want to double-check the perl dependancies after SpamAssassin is installed. When you install SpamAssassin via ports, it will check to see if it needs to install any of the required perl dependancies which makes things easy to install and setup. Please change the version of SpamAssassin in the command below. For instance if you are running SpamAssassin 3.1.0, you would substitute 3.1.0 for the 3.x.x in the following command:


# /usr/ports/mail/p5-Mail-SpamAssassin/work/Mail-SpamAssassin-3.x.x/build/check_dependencies

You will get a pretty large output. Don't worry about any optional modules unless you want to install and use them. The optional modules are configured in /usr/local/etc/mail/spamassassin/v310.pre. All you need to do is install the perl module for it and then uncomment it in v310.pre. Pretty easy to do. I have you run this because if it shows something OTHER than the optional modules, you may just want to reinstall the spamassassin port again. If you reinstall and it still doesn't work, I would suggest looking at the support options on the left,

After running the above command, lets clean up the install:


# cd /usr/ports/mail/p5-Mail-SpamAssassin
# make clean 

Configuring SpamAssassin

If you cd to /usr/local/etc/mail/spamassassin/, you will see 4 files. Two of them are .sample files and the 2 others are your SpamAssassin global options. init.pre and v310.pre have many different options to choose from. Enable them at your leisure. We will not be going over them as they are optional settings.

What we need to do is get local.cf setup so run the following:


# cd /usr/local/etc/mail/spamassassin/
# cp local.cf.sample local.cf
# vi local.cf

In local.cf we want to set a few options in here. I will list them individually:

rewrite_header Subject - Leave this commented (#). We will configure qmail-scanner to rewrite the subject for us.
report_safe - Leave this commented. This just leaves the message as Spam or Ham and does not save it as an attachment.
trusted_networks - Leave this commented. We define this globally in qmail in the /etc/tcp/smtp file.
lock_method flock - Leave this commented.
required_score - Uncomment this and set this to around 4.3 or so. I have mine set at 3.9 right now and seems to be catching a lot of spams.
use_bayes - Leave this commented. If you would like to configure bayes, Go to the following page:
http://goodcleanemail.com/index.php?option=com_content&task=view&id=12&Itemid=1
bayes_ignore_header - Leave these commented. The "bayes_ignore_header" lines tell the bayesian filtering code to ignore the headers your users' mail apps will add in bouncing the message. For more information please see http://www.stearns.org/doc/spamassassin-setup.current.html

We are now going to run SpamAssassin via daemontools:


# mkdir -m 1755 /var/qmail/supervise/spamd
# mkdir -m 755 /var/qmail/supervise/spamd/log
# cd /var/qmail/supervise/spamd
# cp /downloads/qmailrocks/spamd-run run
# chmod 755 run
# cd log
# cp /downloads/qmailrocks/service-any-log-run run
# chmod 755 run

And then create the service: 


# ln -s /var/qmail/supervise/spamd /service/

After a few seconds run: 


# svstat /service/spamd/ /service/spamd/log/

And you should see something like: 


/service/spamd/: up (pid 50481) 4 seconds
/service/spamd/log/: up (pid 50482) 4 seconds


We now want to check and see if spamassassin has any errors. Run the following command: 


# spamassassin --lint

The first time you run it, you might see

warn: config: created user preferences file: /tmp/.spamassassin/user_prefs

This error is fine. it's just telling you it's creating a user_prefs file for username qscand.

If you don't get any errors, SpamAssassin is configured correctly! 

Now we need to remove the startup script in /usr/local/etc/rc.d:


# rm /usr/local/etc/rc.d/sa-spamd

Optional: Additional Steps

The following is recommended if you continue to get spam and want to combat it:

Optimizing SpamAssassin - How to catch more spams

Thats it! SpamAssassin is installed, configured and also running. We are all done! WOOT!

Setting up ClamAV