Home -- Tutorials -- Quickies -- Manual Pages -- Search -- Feedback -- About The Site -- Forum
Installing SpamAssassin on FreeBSD with Sendmail + Procmail
added 2.11.2005 -- written by David van Geyn


Article Description: Setting up Spamassassin seemed like a large task... However, with FreeBSD Ports it is very easy to do. Same would go for Gentoo Portage, and I imagine, Debian apt-get... It's just a pain to do manually because you have to install a bunch of perl modules..
I had been using SpamBouncer for about two years with it doing a great job of catching spam e-mail that had been sent to me. However, I wanted something that was quicker in scanning. I was having some real problems with SpamBouncer (not that I think it doesn’t work well; on the contrary, I think it worked very well, and was very good at sending spam to my Spam folder) handling large e-mail messages. Admittedly, my server that handles my e-mail is still a Pentium 166 with 256 MB of RAM running FreeBSD 4.11-STABLE. But sometimes SpamBouncer would use 30, 45, 60, or even 90 minutes of CPU time processing a single 5 MB e-mail message (with an attachment, obviously). It did a great job when I had viruses sent to me. They never appeared in my inbox and were successfully sent off to my Virus folder. It was just that, in light of the slow server, and the sometimes long processing times, I was getting a bit irritated waiting for certain messages. It also seemed to sometimes spend several minutes scanning a simple 1 or 2 paragraph e-mail.

On a side note, if anyone has some computer components newer than this Pentium 166 that you would like to donate, I would be very gracious. Any upgrade to my mail server would be very welcome! Contact me using the ‘Contact Us’ link above, or e-mail ‘webmaster AT itpronto DOT com’.

It was time to try something new. I had heard many good things about SpamAssassin, but thought that installing it was a bit of a daunting task.

I wanted to install it and have procmail execute it, rather than have all incoming messages sent through SpamAssassin. This was so that I have it not enabled on all e-mail accounts on the system, and also so that I could send mail from mailing lists to the appropriate folders still, using procmail. I suppose for that I could have installed SpamAssassin on all incoming mail, then still used procmail to deliver the mail to the proper folders, but I was already using procmail for SpamBouncer, so figured that I might as well just keep on using procmail to execute the appropriate spam filter.

The tutorial follows:

1) If you do not have procmail installed, you should install that first.

cd /usr/ports/mail/procmail
make install

2) First, SpamAssassin requires Perl 5.6.x or later. FreeBSD 4.x does not have that by default. It still has Perl 5.005_03. Time to use ports!

cd /usr/ports/lang/perl5.8
make install (go make some coffee here, this will take a while)

3) You will get a nice message after it is done installing. This will detail how to use the newer Perl version. To use the new Perl by default, you need to execute:

rehash (this will just refresh your paths, so that use.perl will be found now)
use.perl port

4) Now that you have Perl 5.8.x installed, you are ready to install SpamAssassin.

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

5) This will install SpamAssassin along with its dependent ports (which are mostly Perl modules). The SpamAssassin binary that you will later configure procmail to execute will be located at:

/usr/local/bin/spamassassin

6) Now it’s time to create a .procmailrc in the home directory of the account you want scanned for spam. Use vi or your favourite editor.

vi ~username/.procmailrc

7) Put the following in .procmailrc, modifying ‘username’ to be your username.

SHELL=/bin/sh
PATH=/usr/bin:/bin:/usr/local/bin:.

DEFAULT=/var/mail/username

MAILDIR=$HOME/mail # You'd better make sure it exists
LOGFILE=$HOME/ProcmailLog
LOCKFILE=$HOME/.lockmail

:0fw: spamassassin.lock
| /usr/local/bin/spamassassin

8) Now you can save the file and close vi (or your favourite editor). If you want detected spam to be delivered to a different folder, add these lines to your .procmailrc also. Make sure the folder already exists, and make sure that $HOME/mail exists above. Below, the folder is called ‘Spam’, so spam will be delivered to $HOME/mail/Spam. I recommend leaving these lines out until you know that SpamAssassin is working properly.

:0:
* ^X-Spam-Status: Yes
"Spam"

9) Again, save and close your editor (if you made these changes). Now you need to set up your .forward file to forward your incoming mail to procmail, and through procmail, to SpamAssassin. Open ~username/.forward in your favourite editor. This file should just contain one line, like below. Make it so!

"|exec /usr/local/bin/procmail"

10) Now, try sending mail to your account. See if procmail processes it (you can examine ~username/ProcmailLog to see if it handled the message). If it did, and SpamAssassin worked, then you should have some new e-mail in your inbox. Take a look at the message headers. You should see lines like these:

X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on radium
X-Spam-Level:
X-Spam-Status: No, score=0.2 required=5.0 tests=FORGED_RCVD_HELO,NO_REAL_NAME autolearn=no version=3.0.2

11) I am really happy with SpamAssassin so far. It doesn’t spend more than 30 seconds processing an average message (remember, this is a Pentium 166), and it catches everything so far. I have not tweaked the default settings at all. I very much like the way SpamAssassin changes the incoming message to tell you why it thinks it is spam, and attaches the spam message to the new message so that you can view it, if you so please. Below is a sample modification to an e-mail it detected as spam:

Spam detection software, running on the system "radium", has
identified this incoming email as possible spam. The original message
has been attached to this so you can view it (if it isn't spam) or label
similar future email. If you have any questions, see
the administrator of that system for details.

Content preview: Hi! We have a new product that we offer to [...]

Content analysis details: (13.0 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
1.9 SUBJECT_DRUG_GAP_C Subject contains a gappy version of 'cialis'
1.5 RAZOR2_CF_RANGE_51_100 BODY: Razor2 gives confidence level above 50%
[cf: 100]
0.1 RAZOR2_CHECK Listed in Razor2 (http://razor.sf.net/)
0.6 URIBL_SBL Contains an URL listed in the SBL blocklist
[URIs: ejrhxw322.com]
2.0 URIBL_AB_SURBL Contains an URL listed in the AB SURBL blocklist
[URIs: ejrhxw322.com]
0.5 URIBL_WS_SURBL Contains an URL listed in the WS SURBL blocklist
[URIs: ejrhxw322.com]
2.0 URIBL_OB_SURBL Contains an URL listed in the OB SURBL blocklist
[URIs: ejrhxw322.com]
3.9 URIBL_SC_SURBL Contains an URL listed in the SC SURBL blocklist
[URIs: ejrhxw322.com]
0.0 DRUGS_ERECTILE Refers to an erectile drug
0.4 FROM_HAS_ULINE_NUMS From: contains an underline and numbers/letters


12) If you are having problems, contact me (the ‘Contact Us’ link above, or ‘webmaster AT itpronto DOT com’). It is possible that since I did this a couple nights ago I have missed something, and if so, I would like to correct it for future visitors.

Note Added on February 13, 2005

To speed up spam processing time, I recommend using spamd and spamc instead of the spamassassin executable. To do this, start up spamd on bootup with this line in /etc/rc.local:

/usr/local/bin/spamd -c -d -r /var/run/spamd.pid &

Then in your .procmailrc, instead of running:

/usr/local/bin/spamassassin

Change this to:

/usr/local/bin/spamc

Your spam should then be processed much faster, and, by default, spamc will not pass a message larger than 250kBytes to spamd. What kind of spam is that big, anyway? When using just spamassassin, it would process any and all messages, which can take a heck of a lot of memory on a 10MB e-mail!
© Copyright 1998-2008 VANGEYN.Net, unless otherwise noted.