Double-pass Spam filtering with GMail and procmail

Just to remember the hack (and to share with those who may not be aware of it) here is how to use GMail as a Spam filter.

First, go to your GMail settings and activate a forward to your main email address.

When it’s done, any non-SPAM email that arrives to your GMail account will be forwarded (note that you can keep a copy in GMail, this is a great combo to have a backup of your emails).

Then, back to your email server side, you need to bounce all incoming emails to your GMail account; but we don’t want to create an infinite loop, so we’ll make sure we don’t bounce an email that comes from GMail’s forward (thanks to the X-Forwarded-For header).

# forward to gmail account for spam filtering - cf http://mboffin.com/post.aspx?id=1636
:0
* !X-Forwarded-For: YOURACCOUNT@gmail.com YOU@YOUREMAILSERVER
{
    :0fw
    | formail -IDelivered-To
    
    :0
    ! YOURACCOUNT@gmail.com
}

And Voila! That’s all you need, now all your emails go through the following flow:

Your mail server -> GMail -> GMail's Spam filter -> Your mail server