Dropping Spam with Postfix and SpamAssassin on GoDaddy’s Dedicated Servers

We recently ran into a situation where one of our users was receiving a large amount of spam to their forwarded email account. Our setup is a dedicated server running Simple Control Panel at Godaddy. We handle email for a few clients and this one in particular was receiving 100’s of spam emails every hour.  Pretty much as soon as we set up this client, we started hitting our 1,000 SMTP Relay limit which prevented us from sending any further emails for any other client on the server.

There is a simple fix to this that I had a difficult time finding so I decided to create a post on this for anyone else who might run into this issue.

The first thing I tried was to turn on SpamAssassin through the Simple Control Panel (log in to your control panel, choose “Email” from the “Server Configuration” section, and choose “Filter incoming email using SpamAssassin”).  The result of this is that SpamAssassin started analyzing the emails coming in and marking them as Spam.  This didn’t fix the problem because the emails were not being dropped, but were instead being forwarded onto the receipient, just now with the “SPAM” designation in the message subject.

The only solution I discovered was to utilize Postfix’s header_checks.  This uses a regular expression to check the header of the email message and then apply a rule to the message accordingly.  Here’s what we did.

  1. edit the /etc/postfix/header_checks file.
  2. add the following line to the bottom of the file:

    /^X-Spam-Flag:.YES/ DISCARD spam

  3. edit the /etc/postfix/main.cf file an make sure the following line is in your file (it may just be commented out):

    header_checks = regexp:/etc/postfix/header_checks

  4. Now restart your postfix process by using the following command:

    postfix reload

What this does is look for the existence of “X-Spam-Flag” in the header of the message.  This flag is put there by SpamAssassin, so it is important that SpamAssassin is running.  Once it sees the “X-Spam-Flag”, it will discard the message.  This will effectively prevent your server from forwarding any spam emails onto your user’s email accounts.  So far this has worked out well for us.

Tags: , , , , ,



Leave a Reply