Blocking SPAM using Postfix header_checks and SpamAssassin

We have dedicated server with Godaddy running Postfix as a mail sever and SpamAssassin as a mail filter. There are some contact mails specified on our websites, which were getting 1000’s of spam mails daily. SpamAssassin is active on our server but it was just adding extra [SPAM] in the subject of the emails. I was looking for how to discard these mails, instead of just modifying the subject of the mails.

Here is the solution which I found.

1. You should have SpamAssassin active on your server, which will analyze the mails coming in and mark them as SPAM. If SpamAssassin is not active, then you can activate on Godaddy dedicated server using the Simple Control Panel.
2. Next, edit the /etc/postfix/header_checks file, which uses a regular expression to check the header of the email message and then apply a rule to the message accordingly.

3. add the following lines to the bottom of the header_checks file:

/^X-Spam-Flag: YES/ DISCARD SpamAssassin Confirmed Spam Content
/^(Subject: \[SPAM\])(.+)$/ DISCARD Spam Content
/^X-Spam-Level: \*{15,}.*/ DISCARD

You can checkout more header_checks rules here :

4. In /etc/postfix/, add header_checks = regexp:/etc/postfix/header_checks

5. Now reload postfix configuration using the following command
postfix reload or service postfix restart

What this does is, it will check for the rules specified in the header_checks file and effectively discard the spam emails from forwarding into your users email accounts.

More Information :

Related Posts: