User Tools

Site Tools


archive:freebsd_install_spamassassin

How To Install Spamassassin On FreeBSD

Installing SpamAssassin

Installing SpamAssassin is quite easy from ports, and finishiing up only takes a few minuttes.

cd /usr/ports/mail/spamassassin
make WITHOUT="SPF_QUERY" WITH="RELAY_COUNTRY PYZOR RAZOR" install clean BATCH=yes

Now be aware even though we are marking Relay_country and Pyzor as to be installed it does not automatically activate them, but it gives you the option to enable them later on using the SpamAssassin configuration files if you would like to.

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
vi local.cf 

Modify the configuration file

We need to edit 2 lines

TO BE REMOVED START
We are replacing Qmail-Scanner with Simscan “Qmail-Scanner” will do the rewriting of the subject for us. Trusted networks will bee handled through the “smtp.cdb” file in “/etc/tcp”.
TO BE REMOVED STOP

Find this line.

# rewrite_header Subject *****SPAM*****

Remove the # and replace the line with the following.

rewrite_header Subject :SPAM:

Next find this line.

# required_score 5.0

Remove the # and set a score that will mark mail 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 4.0

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.

cpan
install IP::Country::Fast
exit

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

vi /usr/local/etc/mail/spamassassin/v310.pre

Find this line

loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject

And below that add the following.

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 most likely just spelling errors. The error message will tell you what to look for.

Setting up Spamassassin through 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 check if everything is running as intended.

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

You should get a message like below.

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

Delete the 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

vi /usr/bin/qmailctl

Find the following lines and remove the # in front of all of them.

# 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 above lines should 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
archive/freebsd_install_spamassassin.txt · Last modified: 24/11/2023 12:33 by Allan