Michael Sage
← Field notes
tech 22 October 2022

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 lang="shell"></span 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.