Reject mail by pattern match on postfix

For a while I’ve been using a setup where every time I sign up to a website, I use a unique recipient delimiter for that site (eg base.reddit@mydomain for reddit) so I can avoid spam and see who is leaking addresses to third parties.

Now that some of these addresses have been leaked, the easiest way to start filtering them would be just to procmail them to /dev/null, but I was wondering, if there is a way to configure postfix to reject emails to a specific delimiter. So for example, let base.reddit@mydomain through, but send a MAILER DAEMON error for base.godaddy@mydomain.

The answer I found was with postfix header_checks.

So, in main.cf, addd:

header_checks = regexp:/etc/postfix/header_checks

and in the header_checks file, use the syntax:

/regex_pattern/ ACTION

So, my rules look like this:

/^To: base.godaddy@mydomain/ REJECT

Thanks to this blog post for the info!

comments powered by Disqus