06.24.06

Double-Pass Spam Filtering with Gmail

Tagged as ,

In my continuing battle against spam, I’ve now implemented double-pass spam filtering, using Gmail as my first line of defense and DreamHost’s SpamAssassin installation as the second. I got the idea (and most of the implementation) from MBoffin.com, and have added a page to the DreamHost Support Wiki explaining how to do it using the default setup (i.e., no custom-installed applications) on that host.

The way it works is that all incoming email on my DreamHost account is scanned for the presence of a special forwarding-only Gmail address. If the address is not found, the message is forwarded to Gmail. Gmail decides whether the message is spam, in which case it’s held in the Spam folder, or not, in which case it’s sent back to the DreamHost server. DreamHost again checks for the required address, and this time finds it, because Gmail has inserted it into the headers. Next the message goes through SpamAssassin, which assigns a score depending on how “spammy” the message looks. I’ve set SpamAssassin to quarantine anything with a score of 5.0 or greater, and to tag the subject line but pass anything with a score of 3.0-4.9.

Technically, I’m using a triple-pass filtering system, because Apple’s Mail.app has its own filtering rules. So far, however, it looks like Gmail and SpamAssassin won’t need any extra help.

If you’d like to try it yourself, note that you’ll need to dedicate a Gmail address to this purpose — everything going to that address will be forwarded to your DreamHost account, so don’t use an address you’re already using for other things. If you need a Gmail invitation, feel free to ask me for one — email nicholas at acetylene dot net.

UPDATE: It appears that Gmail is somewhat inconsistent in its use or formatting of the X-Forwarded-For: header, leading to infrequent (but annoying) infinite loops. (Actually, procmail is intelligent enough to reject the message rather than forwarding it a second time, but that means it stays in Gmail and never arrives in my IMAP inbox.) I’ve simplified the rule to avoid this problem in the future; now all procmail is looking for is the address of my forwarding-only Gmail account. As long as it finds that somewhere, it’ll send the message to my IMAP inbox.

UPDATE 2: I was wrong: Gmail wasn’t being inconsistent; DreamHost’s procmail was. Seems it sometimes thought the mail was looping when it saw its own Delivered-To: header, so I’ve edited the DreamHost wiki to include a formail pipe that removes that header before forwarding to Gmail.

1 Comment »

  1. Acetylene.net » Review: Postini Managed Spam Filtering Said:

    March 28, 2007 at 7:40 am

    [...] considered spam. I eventually decided to combine DreamHost’s filters with Gmail, and wrote a blog post and a wiki article about my technique. For a while, that worked beautifully, but something must [...]

Leave a Comment