How to filter mail with postfix header_checks
There’s a lot of static on Google about this, so I’ll just re-document it here. You can filter email in postfix with the header_checks parameter in your main.cf. You specify that you want to use regular expressions and you specify the file that holds them:
#main.cf header_checks = regexp:/etc/postfix/header_checks
The syntax in the header_checks file is:
See a full list of possible actions here
I’m doing three things in the example.
– If the sender’s email address starts with “spammer”, then REJECT it.
– If an email is sent to bob on my server, forward it bob’s real email address
– If the subject contains “Viagra” then discard it.
#/etc/postfix/header_checks /^From: "spammer/ REJECT /^To: firstname.lastname@example.org/ REDIRECT email@example.com /^Subject:.*viagra/ DISCARD
Here are a bunch of rules for those anti-virus spams.