freebsdrocks.net was started originally as nospam.mine.nu.
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/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
DOCS
SSL
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/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.
here are the port locations for the optional plugins:
Digest::SHA1 - /usr/ports/security/p5-Digest-SHA1
Mail::SPF - /usr/ports/mail/p5-Mail-SPF
Geo::IP - /usr/ports/net/p5-Geo-IP
Net::CIDR::Lite - /usr/ports/net/p5-Net-CIDR-Lite
IO::Socket::INET6 - /usr/ports/net/p5-IO-Socket-INET6
Mail::DKIM - /usr/ports/mail/p5-Mail-DKIM
DBI - /usr/ports/databases/p5-DBI
LWP::UserAgent - /usr/ports/www/p5-LWP-UserAgent-POE
Net::Patricia - /usr/ports/net/p5-Net-Patricia
After running the above command, lets clean up the install:
# cd /usr/ports/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/
# vi local.cf
In local.cf we want to set a few options in here. I will list them individually:
NOTE about simscan or qmail-scannerIf you plan on using simscan you will have to change the rewrite_header Subject as seen below. If you are using qmail-scanner then this line will need to be commented (#).
rewrite_header Subject :SPAM: - uncomment this line and add :SPAM: as the subject
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. We will get to this later.
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 ~root/qmail/spamd-run .
# mv spamd-run run
# chmod 755 run
# cd log
# cp ~root/qmail/service-any-log-run run
# chmod 755 run
# mkdir /var/log/qmail/spamd
# vi run
In the run file change the last line to match the following:
exec /usr/local/bin/multilog t n20 s1048576 /var/log/qmail/spamd
Before we run the symlink to the SpamAssassin service, you are required to do an initial run of sa-update before doing so. Run the following command:
# /usr/local/bin/sa-update
# /usr/local/bin/sa-compile
Now we can 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
Thats it! SpamAssassin is installed, configured and also running.