Guide On How To Install SpamAssassin On FreeBSD

Guide On How To Install SpamAssassin On FreeBSD 2017-08-04T09:50:15+00:00

A Step By Step Guide On How To Install SpamAssassin On FreeBSD
Oh boy the battle to get back in control of your mailbox. This is where SpamAssassin comes in. This guide will have you run a simple setup. If that’s not enough there’s also a guide on catching more spam with SpamAssassin.

Right I assume you know that spamassassin is a perl thing. On the other hand I also assume you are running qmail. I know I’m making a lot of assumptions. Even so perl is a requirement but changes are that you already have perl installed. I would highly recommend you to use perl 5.24 the current version shipped with FreeBSD. You can check your perl version like this.

perl -v

You will get an output with the version number of perl among other things.

This is perl 5, version 24, subversion 1 (v5.24.1) built for amd64-freebsd-thread-multi

Copyright 1987-2017, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

Installing SpamAssassin

cd /usr/ports/mail/spamassassin
make WITH="RELAY_COUNTRY PYZOR RAZOR" install clean

Don’t check SPF_QUERY as the “Smtp Run File” already has this option built in. For the rest of the popups just accept the default settings. Please be aware that even though there are check boxes at various “applications and options” they will not automatically be activated like “Razor or Relay Country” that are checked. It does however install them and gives you the option to enable them later on using the SpamAssassin configuration files. Right let’s get the configuration files in place and modify them to our needs.

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

Modify the configuration file

We need to edit 1 line and 1 line only don’t edit anything else. “Qmail-Scanner” will do the rewriting of the subject header for us. Trusted networks will bee handled through the “smtp.cdb”. So we need to edit this file /usr/local/etc/mail/spamassassin/local.cf in that file find the following line.

# required_score 5.0
make WITH="RELAY_COUNTRY PYZOR RAZOR" install clean

Remove the # mark and set a score that will mark mails as spam. I have mine set to 3.4 and i have not gotten any false positives yet but still catching tons of spam. Mine looks like this.

required_score 3.4

Update SA rules

We need to fetch the latest “SA” rules this is a simple one line command. I strongly suggest putting this in cron.

sa-update

Install extra modules

In order to catch a bit more spam we will install a few extra modules. This is done through cpan. So first start up cpan like this.

cpan

Next install the following module.

install IP::Country::Fast

Once installed exit cpan like this.

exit

Now lets enable IP Country this in done in the file /usr/local/etc/mail/spamassassin/v310.pre find the following line.

# WhitelistSubject - Whitelist/Blacklist certain subject regular expressions
#
loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject

And below “WhiteListSubject” add the following line like this.

# WhitelistSubject - Whitelist/Blacklist certain subject regular expressions
#
loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject
loadplugin IP::Country::Fast

Now let’s check if the configuration files have any errors.

spamassassin --lint

If this runs without errors we can continue. If there are errors it’s probably just typos. The error message will tell you what to look for.

“Setting up Spamassassin To Be Run By Daemontools”

mkdir -m 1755 /var/qmail/supervise/spamd
mkdir -m 755 /var/qmail/supervise/spamd/log
cd /var/qmail/supervise/spamd
fetch http://www.xfiles.dk/content/files/freebsd-qmail/spamd-run
mv spamd-run run
chmod 755 run
cd log
fetch http://www.xfiles.dk/content/files/freebsd-qmail/spamd-log-run
mv spamd-log-run run
chmod 755 run
mkdir /var/log/qmail/spamd

Enable the service.

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

And let’s check if things a woring as intended.

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

You should get an output very much like below.

/service/spamd/:     up (pid 667) 1456 seconds
/service/spamd/log/: up (pid 675) 1456 seconds

Delete the original startup script that Spamassassin created under the installation so it doesn’t startup twice.

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

“Adding Spamassassin To Qmailctl”

In order to control spamassassin from qmailctl we need to edit this file /usr/bin/qmailctl find the following lines and remove the # mark.

# if svok /service/spamd ; then
# svc -u /service/spamd /service/spamd/log
# echo "Starting spamd"
# else
# echo "spamd supervise not running"
# fi

# echo " spamd"
# svc -d /service/spamd /service/spamd/log

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

# echo "Pausing spamd"   
# svc -p /service/spamd

# echo "Pausing spamd"
# svc -c /service/spamd

# echo "* Restarting spamd"
# svc -t /service/spamd /service/spamd/log

All of the lines above should now look like this.

if svok /service/spamd ; then
svc -u /service/spamd /service/spamd/log
echo "Starting spamd"
else
echo "spamd supervise not running"
fi

echo " spamd"
svc -d /service/spamd /service/spamd/log

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

echo "Pausing spamd"   
svc -p /service/spamd

echo "Pausing spamd"
svc -c /service/spamd

echo "* Restarting spamd"
svc -t /service/spamd /service/spamd/log

Now restart qmail in order for the changes to take effect.

qmailctl restart

In case you need to tweak or catch more spam I’ve written a guide for that [here]

And we are done here.

Spell checkers don’t – Grammar checkers don’t either.