So, you want to install spamassassin, you've looked at the docs and gone huh? Then this doc is for you.
What is spamassassin?
Spamassassin is a spam identification and tagging utility. It doesn't filter or delete spam, it just tags it as spam, it is also capable of learning as it goes. You need to use another utility to actually delete or file away the spam. Luckily most spamassassin installations use an application called procmail to pass email to spamassassin for processing, procmail can easily handle deleting or filing the spam.
Possible installations
There are a number of ways to install spamassassin.
- 1. On a remote IMAP server you have shell access to.
- 2. On a local system you read mail on.
- 3. On a remote POP3 server you have shell access to.
- 4. On a remote POP3/IMAP server you do not have shell access to.
- 5. On a remote server you read mail on via shell access.
I will be concentrating on options 1, 2 and 5, which all can be configured the same way. Option 3 can use the first part of this install, but the filtering/deletion must be done by the POP3 client. Option 4 require a system-wide install which must be done by the sysadmin. Shell access is access via ssh or telnet.Ę
Installing spamassassin
This part is easy. The spamassassin INSTALL doc covers the options pretty well, including dependencies. You can install via Perl CPAN, downloading the Tarball or via the package management tool of your choice (Personally I used apt-get on my Debian system). You will also need to install procmail if it isn't installed on your system already, and an installed and configured Mail Daemon (Both of these are probably already installed.)
As we are going to use procmail to pass email to spamassassin for evaluation, the first step, after installing the software itself, is to set up a procmail config file. This file is called .procmailrc and it lives in your home directory. So fire up the text editor of your choice, and open .procmailrc if it already exists, if it doesn't, you'll want to open a new document.
First off, we need to locate the spamassassin binary. To do this run:
which spamassassin
In a console. This will return the full path to spamassassin. In my case it was:
/usr/bin/spamassassin
Now that we know where spamassassin lives, we can add it to the procmail config file. So, we add these 3 lines to the file (preferably at the top, if you already have a procmail config):
:0fw: spamassassin.lock
* < 256000
| /usr/bin/spamassassin
Replace the path to spamassassin on the last line with the correct path from the previous step. The first line tells procmail to forward the email to the program specified on the third line, and create a lock file(which allows only one program at a time to read the email) and the second line prevents multiple copies of spamassassin from running (Which would otherwise cause the system to slow down).
Now save the file as .procmailrc in your home directory. And let it run for a while this way, to ensure that it's only tagging spam as spam and not losing any mail.
The next step is to add a statement to the procmail config to file spam in its own folder. This should be placed immediately after the first statement we added.
Add:
:0:
* ^X-Spam-Status: Yes
spam
This will file all email that spamassassin considers to be spam into a mail folder called spam. Note that spamassassin assigns a numeric score to each email, by default anything with a score of 5 or higher is considered to be spam. Let this run for a while, and check your spam folder to ensure that it's only collecting spam. As to spam it doesnŐt catch, well, we'll leave that for a while, I'll show you how to use the learning features further on.
The last step is to set up a procmail statement to delete spam. This will be based on the spamassassin score, as we want to make sure that we donŐt accidentally delete wanted email. So add this statement between the first statement and the second (Otherwise the spam will be filed before it can be deleted.) The statement is:
:0:
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
/dev/null
Note that the number of '\*' entries denotes the score necessary to be deleted. We've chosen a score of 15 (thus the 15 '\*'s) to ensure we don't delete good email. This can of course be tweaked in the future.
So your .procmailrc looks like this now:
:0fw: spamassassin.lock
* < 256000
| /usr/bin/spamassassin
:0:
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
/dev/null
:0:
* ^X-Spam-Status: Yes
spam
Additional Options:
For Option 3 (Remote POP server) only do step one, as POP3 doesn't support multiple folders. You'll need to use your Mail Clients filtering to sort and delete email that Spamassassin classifies as spam. (Well, actually you can do the deletion on the server as well, but I don't recommend it.)
Ę