Sendmail, Procmail and SpamAssassin email filtering How-To
|
How to Install and Configure SpamAssassin with Sendmail on Linux Copyright© 2003 by Rubin Bennett, All Rights Reserved. Written by Rubin Bennett (rbennett@thatITguy.com). Comments to me, flames to /dev/null! |
|
|
First, the usual disclaimer... I hereby assume absolutely no reponsibility for any damage resulting to your system by your use of the information contained in this website. Any info here is for reference purposes ONLY. If it works for you, great. If it doesn't, don't come crying to me. |
|
|
Why do this: Spamassassin: TAGS Spam, but IT DOES NOT DO ANYTHING ELSE TO IT!!! It Can't delete your spam, it can't reply to it. It can't forward it. It looks at it, and either marks it as spam or not. That's it. Period. Procmail: Procmail can (and will, if you ask it to) filter, scan, delete and otherwise adulterate your email. Procmail is also how your email will get sent to SpamAssassin (more on that later). Procmail is a Mail Delivery Agent, or MDA. Sendmail: Sendmail is the program that receives the email coming into your server from another server or mailer. Sendmail can be configured to use SpamAssassin directly via a Milter, but that's another subject. Sendmail is a Mail Transport Agent, or MTA.
NOTE: I use Sendmail on Mandrake. Mandrake installs Postfix by default. Postfix sucks (IMO). It's a resource hog, and it's slow. The first thing I do when I install a new Mandrake system is install sendmail (urpmi sendmail sendmail-cf), fix the stoopid typo in /etc/mail/sendmail.mc (the path to m4.cf is wrong) and rpm -e postfix. Postfix can use SpamAssassin (via procmail or Maildrop) but there's loads of documentation out there on that setup. Procmail then takes the message and delivers it to the users' mailbox (wherever that may be, usually /var/spool/mail/username).
User logs in to check their mail (via their Mail User Agent, or MUA such as Eudora or (bleah) Outlook) and receives their spam payload (oh, and if they're lucky, a couple of legit messages too). Procmail will look at it's config and realize that it's supposed to run it through SpamAssassin (either via spamassassin, or spamc if you're using the daemonized version). SpamAssassin/ spamc will then RETURN THE MESSAGE TO PROCMAIL, after determining whether the mail is spam or not.
Procmail will look for the appropriate headers (X-SPAM-STATUS=yes) and act accordingly. It can simply send it on and let the end users' email client filter on those headers, or it can take a variety of actions, from dumping the message altogether to putting it in a different mailbox to, well, you get the picture. My /etc/procmailrc is below:
:0fw
# Work around procmail bug: any output on stderr will cause the "F" in "From"
:0 fhw You can use procmail to do fun things like summarily drop executable attachments, search for strings in the messages etc.. Read # man procmailrc. Now, test it all out... find a piece of spam (there's a sample in /usr/share/doc/spamassassin-{VERSION}) and do the following: [root]# cat /usr/share/doc/spamassassin-{VERSION}/sample-spam.txt | spamassassin You should see your message return to stdout (your terminal screen) with a bunch of extra messages added by spamassassin (example below): #> cat /usr/share/doc/spamassassin-2.60/sample-spam.txt | spamc
Subject: Test spam mail (GTUBE)
This is the GTUBE, the
If your spam filter supports it, the GTUBE provides a test by which you XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
You should send this test mail from an account outside of your network. Now that it's installed and working, you'll want to set up procmail to do something about those spammy messages (this is my ~/.procmailrc): # Mails with a score of 5 or above get sent to my Junk mailbox # Note that I use IMAP... this won't work if you use POP...
:0: So, there you have it... a working installation of SpamAssassin, teamed up with Sendmail and Procmail! I hope this was helpful; if so great (send me a line on the feedback page if you feel like it) or an email to rbennett_at_DIESPAMMERS_thatitguy.com. Suggestions on improvements welcome as well! NEW!!! A friend and I have been working on a system to get rid of the Junk folder called the SpamDigester. Basically, the Digester takes messages tagged as Junk by SpamAssassin and drops them into a holding area (actually, a MySQL database), and then sends periodic digests to the users for whom it's holding messages. Each Digest contains a synopsis of the messages for that user, and an HTML form asking what to do with each of them (Delete/ Deliver/ Deliver and Whitelist). See more here: http://spamdigester.org New New!!! We have largely stopped development work on the SpamDigester, because we found Untangle (http://untangle.com). Untangle does pretty much everything that the SpamDigester does, but we don't have to maintain the codebase. Sweet. |
|
