I recently setup a Ubuntu Dev server and wanted to set it up so that it would use the Google SMTP relay to send emails. After fighting with it for a while I was able to setup Postfix to use Google SMTP relay. Here is how it is done:
This config changes sender addresses from both local originated, and relayed SMTP mail traffic:
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check
Rewrite envelope address from email originating from the server itself
Rewrite from address in SMTP relayed e-mail
/From:.*/ REPLACE From: email@example.com
Thats very useful if you’re for instance using a local relay smtp server which is used by all your multifunctionals and several applications.
If you use Office 365 SMTP server, any mail with a different sender address than the email from the authenticated user itself will simply be denied. The above config prevents this.