Shami's Blog

Sysadmin, Because Even Developers Need Heroes

Adding 'on behalf of' To Outgoing Emails With Postfix

2016-04-28 by Mohammad H. Al-Shami

I used to be a big fan of Mandrill. I used to use it as an email gateway for my personal servers. It’s easy to use and it’s cheap (Or free if you send less than 12,000 emails per month). I liked not having to setup SPF, DKIM, and DMARC for my small setups. Even for smaller clients I wouldn’t bother with that and just use Mandrill. Emails just show up with the following sender

[email protected]; on behalf of; [email protected]

This was convenient because destination mail servers would check Mandrill’s SPF and DKIM instead of checking the sender’s.

And then MailChimp decided to change their business model and Mandrill was no longer an option. I thought about checking other services like SparkPost or MailGun but then decided on building my own. You never know when they’d decide to do what MailChimp did.

Just add the following lines to (Those paths are for FreeBSD, your paths might vary)

sender_canonical_maps = regexp:/usr/local/etc/postfix/canonical
sender_canonical_classes = envelope_sender
header_checks = regexp:/usr/local/etc/postfix/my_custom_header
# /usr/local/etc/postfix/canonical
/.*/ [email protected]
# /usr/local/etc/postfix/my_custom_header
/^Subject:/i PREPEND Sender: [email protected]

What this does is add [email protected] as the Return-Path of all outgoing emails, and add a Sender header to the message. You might want to tweak that logic a bit.

About Me

Dev gone Ops gone DevOps. Any views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.