Introduction
This is a short guide describing the steps I took to install and configure Fetchmail to download mail from my many POP3 mail accounts, then process the messages through Spamassassin via Postfix on a Slackware 10 installation. This will probably work on other systems as well, but I use Slackware 10 on my box at home. Basically, I wanted a way to process messages downloaded via Fetchmail through Spamassassin. Because I am worried about not getting misclassification mail, I just want Spamassassin to process the mail and mark it as spam or ham, I will let my mail client sort everything out from there.
Spamassassin
The first thing you can install and configure is Spamassassin. I simply followed the instructions in the INSTALL document on their web site to download and install the software via CPAN (as root):
If you don't get any error messages, then you've installed Spamassassin successfully. Note that some RedHat systems have problems installing Spamassassin. If you get some weird errors (sorry, I don't remember the error), try this at a command prompt:# perl -MCPAN -e shell cpan> o conf prerequisites_policy ask cpan> install Mail::Spamassassin cpan> quit
..and try running the install process again.# export LANG=en_US
Configuring Spamassassin is pretty simple, you just need to configure the local.cf file provided by Spamassassin. On both my RedHat boxes and Slackware box, it is located in /etc/mail/Spamassassin. My simple local.cf file can be found here, which you are welcome to use as an example.
Start Spamassassin with the following command:
# /usr/bin/spamd -d
Postfix
Sendmail is great, I use it on my boxes I administer at work, but I find it lacking in several areas, most notably security. I also wanted to force Sendmail to process messages through Spamassassin, which can only be done with a milter such as mimedefang or spamass-milter, both of which I don't like very much. After discussing the alternatives (Exim, Postfix, Qmail, etc..) with a few friends, I decided to give Postfix a try.
Both Slackware and RedHat Linux is installed with Sendmail installed, so you will need to uninstall these packages in order to use Postfix. In my particular case, I uninstalled Sendmail by using Pkgtool. To access this tool (as root):
Press R to select the Remove Package option, then press Enter. The pkgtool will scan for packages installed on the computer. Scroll down until you locate Sendmail on the list, press the Space Bar to select the package and press Enter. The package should be uninstalled now.# pkgtool
For RedHat/Fedora, you can use RPM to locate and remove the package. To do this:
..Be sure to replace the [sendmail package] with the name that RPM returns.# rpm -qa | grep sendmail # rpm -e [sendmail package]
To install Postfix, I downloaded the package from Linux Packages.net, and then ran (as root):
..[name of package] needs to be replaced with the full name of the file you downloaded, including the extension (.tgz).# installpkg [name of package]
Configuring Postfix was quite easy, I just followed the examples provided in the documentation. I have included a sample file here (replace "mydomain" and "myhost" with your domain and host settings). NOTE: I do not use postfix to send or receive mail directly to and from my Linux box, so I do not know if my configuration settings will allow these types of actions. Postfix is there simply to process mail from my remote mailboxes and send me reports from cron output.
The last thing you need to do is configure Postfix to pipe mail through Spamassassin. Easy enough. First, I created a shell script called sa-filter. I put this script in my /usr/bin/ directory.
Now that I've written what equates to a milter script, I have to insert the command to execute this into my master.cf config file for postfix. This file can be found in the /etc/postfix/ directory. Add the following lines to the bottom of the file:#!/bin/bash /usr/bin/spamassassin | /usr/sbin/sendmail -i "$@" exit $?
# Spam Filter
spamassassin unix - n n - - pipe
user=nobody argv=/usr/bin/sa-filter -f ${sender} -- ${recipient}
# Change the settings for smtp and smtpd:
smtp inet n - n - - smtpd
-o content_filter=spamassassin:
smtp unix - - n - - smtp
-o content_filter=spamassassin:
...Now you're done with configuring postfix. Restart it.
Fetchmail
Fetchmail came pre-installed on my system and was ready to rock. All I had to do was configure the .fetchmailrc file and create a few users. I created the .fetchmailrc file under my normal user account. Because I have so many mail accounts, I found it easier in regards to client side mail rules to simply create a no login account for each mail account, but I am still only using 1 .fetchmailrc file. So my .fetchmailrc file looks like this (in part):
poll isp1.com
proto pop3
auth password
via pop.isp1.com
user "mylogin"
pass "mypass"
is user1
poll isp2.com
proto pop3
auth password
via pop.isp2.com
user "mylogin"
pass "mypass"
is user2
...and so on. Test your configuration and download live mail (I would recommend you empty your pop boxes and send a test message first in case something is broken) by running the following (as the user you created the .fetchmailrc file under):
..This will show you a "verbose" output of the connection attempts. If all goes well, you can set up a cron job to download your mail regularly using Fetchmail. I did this with crontab, and my mail is collected via my broadband connection every hour. To do this, I created a file in /var/spool/cron/crontabs. I named this file the same name as the username that has the .fetchmailrc file. In this file, I added the following entry:/usr/bin/fetchmail -v
This downloads my mail "silently" and ditches any error output so my mailbox isn't full of errors if something goes wrong.0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * fetchmail -s >/dev/null 2>&1
And that's all there is to it, kids! Have fun!
Last Modified: Friday, October 15, 2004
darkrose@eschew.net
