Skip to content

Additional Postfix Settings that work with sasl xoauth2 (probably just for local mail)

Jamen edited this page Nov 13, 2020 · 5 revisions

Headers can be modified by postfix to add additional information or change existing information to something else.

For example, all mail sent locally from the postfix server shows up as [email protected], but you want it to be a little less generic looking and show more details in the header (e.g. which server sent this email).

This can be achieved with canonical maps and header checks.

Please Note:

The following information can be applied to instances of postfix running on a server configured with sasl-xoauth2 or one that sends to a sasl-xoauth2 configured relay.

edit /etc/postfix/sender_canonical_maps

add the email address that is set up with sasl-xoauth2

/.+/ [email protected]

edit /etc/postfix/smtp_header_checks

add the server name in the replacement From: part and a further identifying email in the <>

/^From:(.*)/i REPLACE From: FancyName <fancyemail - this will be overwritten later>

edit /etc/postfix/header_checks

edit the second line to include the email address that is configured with sasl-xoauth2, the original to/from will be added to a new header field so they can be traced by viewing the headers of the email later on.

/^From\:(\s)?(.*)/i PREPEND X-Original-From: $2
/^From\:.*$/i REPLACE From: [email protected]
/^To\:(\s)?(.*)/i PREPEND X-Original-To: $2

run postmap header_checks smtp_header_checks canonical_names from the /etc/postfix directory

add these lines to your /etc/postfix/main.cf file

smtp_header_checks = regexp:/etc/postfix/smtp_header_checks
header_checks = regexp:/etc/postfix/header_checks
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps

restart postfix and test it with

mail -s test -a 'From: <[email protected]>' [email protected] <<< test

Your message should arrive with the new "FancyName" as well as contain the original sender and extra info in the headers.