Colourful Norwich skyline illustration

Michael Sage

IT, Digital & Culture

Postfix From Rewrite

Quick article about re-writing the from address from postfix. First install the libsasl2-modules.


Add the following to main.cf 


sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check
</pre class="code highlight" lang="shell"></span class="line" lang="shell">

Then create the files and their contents


/etc/postfix/sender_canonical_maps
/.+/ newemail@domain.com

/etc/postfix/header_check
From:.*/ REPLACE From: newemail@domain.com

Reload Postfix and test

mail -s “Test Subject” user@example.com < /dev/null

Check the mail logs to see if it’s successful. This trick is really useful if you use a 3rd party to relay email and they require some form of domain or address authentication.