User Tools

Site Tools


how_to_filter_mail_with_postfix_header_checks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

how_to_filter_mail_with_postfix_header_checks [2018/04/21 03:41] (current)
Line 1: Line 1:
 +====== 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:
 +/​regex_pattern/​ ACTION
 +
 +man header_checks for more information REJECT vs DISCARD
 +
 +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: bob@here.com/​ REDIRECT bob@there.com
 +
 +/​^Subject:​.*viagra/​ DISCARD
how_to_filter_mail_with_postfix_header_checks.txt · Last modified: 2018/04/21 03:41 (external edit)