skip to content

Using Gmail as a Spam Filter

Posted by Stoo on 11th June 2009

For some months now I've been running Exim4 as a mail server on a linux box. It's been running well since I set it up but I never managed to set up a spam filter. My knowledge of Exim4, and mail server config in general, is limited, so I've been avoiding changing anything unless I have to.

Of course, the constant run of spam (in the region of thirty or forty emails per day) finally annoyed me enough to do something about it.

I didn't want to set up and configure SpamAssassin, or similar, as I don't have the time or inclination to keep it up to date. I decided to route my email through a Gmail account. I'm sure Google have enough knowledge and resources to keep on top of the spam problem for me.

It was daunting setting it up — I'm never happy when I come to the limits of my knowledge — but it was surprisingly simple. In the settings page of your Gmail account:

  1. click on the 'Forwarding and POP/IMAP' tab,
  2. select the 'Forward a copy' radio button in the Forward section,
  3. enter your non-gmail address in the text field
  4. save your changes and you're done.

This changes your Gmail account to forward any email it receives to your main email account. Now you need to make Exim4 forward your email to Gmail. This was surprisingly simple! In the home directory for your mail account create a file called '.forward' and enter the following:

#Exim filter
if $h_x-Forwarded-For: is not "you@gmail.com your.regular@email.com" then
	deliver you@gmail.com
endif

All this is doing is delivering any email to your Gmail account unless it contains the header x-Forwarded-For. This is the header Gmail sets when it sends the non-spam emails back to your main account.

Save the file, restart Exim and you're done!

Re: Using Gmail as a Spam Filter

I like this idea a lot!

Posted by Tristan on 21st July 2009 reply

Add Comment

Your name OK You must enter your name
Your email address won't be displayed anywhere on the site OK You must enter a valid email address
Input not required:
Optional website address OK
Comment subject OK You must enter a subject
Your comment OK Say something!