[Postfix] Limiting outbound FROM domains

An app on our server allowed customers to pick whatever FROM address they wanted for their email alert including domain. This completely skewed our statistics over at Sparkpost as we attempted to send emails from unverified domains like a.com, none.com, dont.care etc.

I was growing tired of waiting for the developers to move their ass so I decided to step in. This is how you limit your outbound emails to specific domains:

Edit /etc/postfix/header_checks

if /^From:/
!/(^From:.*domain\.com|^From:.*domain\.net|^From:.*domain\.co\.il)/ DISCARD SEND FROM THE RIGHT DOMAINS ASSHOLE
endif

Edit /etc/postfix/main.cf

header_checks = pcre:/etc/postfix/header_checks

Restart or reload Postfix.

And there you have it.
All emails should be of either of domain.com, domain.co.il or domain.net.
The rest will be scrapped.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s