Deleting spam with postfix and SpamAssassin

For years, I’ve been using mutt as my main mail program. I love being able to use mutt in screen and thereby having access to my email from anywhere, with just ssh or PuTTY. Back when I first created this setup, all opensource webmail software then available was still very poor in functionality, which I why I didn’t use webmail for the “access from anywhere” part.

I have a hosted machine, and the MX records of my domains point to it. My mail is being handled by postfix, and spamfiltered by SpamAssassin. Procmail helps me sort mail into different folders upon arrival.

This setup has some disadvantages. Some spam leaks through, which is annoying – since I only receive a few emails every day, a relatively large portion of the mail I see is spam. Also, turning off or reinstalling my hosted machine means emails don’t arrive.

I recently got a smartphone, and wanted to be able to use it to read my email. I briefly considered installing dovecot on my hosted machine to provide IMAP, but decided to try Google Apps instead.

I followed the Google Apps setup document, and set the MX records of one of my domains to Google’s mailservers. That worked fine. Since the free version of Google Apps doesn’t support more than one domain, I then configured postfix on my hosted machine to forward mail sent to my other domains to gmail.

This turned out to have one big disadvantage: with that setup, all spam received by my hosted machine is sent to Google anyway. Sure, SpamAssassin puts spam score headers in the message, but the message is sent to Google whether it’s spam or not. This results in my hosted machine sending 90% spam and 10% real mail to Google.

I was afraid that Google might start seeing my hosted machine’s IP address as evil because of the relatively large amounts of spam, so I looked for a way to prevent most or all of the spam from being forwarded to Google.

This is what I found: http://www.akadia.com/services/postfix_spamassassin.html

See the section called “Create your own Content Filter“. This was exactly what I was looking for.

Steps 1, 3, 4 and 5 worked fine on my Ubuntu server, although there is a typo in the first step (“filer” instead of “filter”). Oh, and I decided to use /var/spamchk as sideline dir, so I created that dir and chowned it to the filter user. I changed the script in step 2 to the following:

I followed these steps and got what I wanted: 90% of the spam my mailserver receives has a score of 10+, and that’s now stored on my server instead of forwarded to Google!

This entry was posted in sysadmin and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.