I'm trying to get email reports from our AWS EC2 instances. We're using Exchange Online (part of Microsoft Online Services). I've setup a user account specifically for SMTP relaying, and I've setup Postfix to meet all the requirements to relay messages through this server. However, Exchange Online's SMTP server will reject messages unless the From address exactly matches the authentication address (the error message is 550 5.7.1 Client does not have permissions to send as this sender
).
With careful configuration, I can setup my services to send as this user. But I'm not a huge fan of being careful - I'd rather have postfix force the issue. Is there a way to do this?
This is how to really do it in postfix.
This config changes sender addresses from both local originated, and relayed SMTP mail traffic:
/etc/postfix/main.cf:
Rewrite envelope address from email originating from the server itself
/etc/postfix/sender_canonical_maps:
Rewrite from address in SMTP relayed e-mail
/etc/postfix/header_check:
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.
(Note: both FROM and TO addresses are matched for replacement for any of generic and canonical tables.)
Using canonical table when mail is received by server is already explained is other answers.
You can rewrite FROM addresses when mail is sent from server using
smtp_generic_maps
.According to postfix documentation :
Then do:
References:
Update: On the advice of an IT friend, I'm running postfix on all my servers, rather than making one cloud mail server. Here's my solution so far:
/etc/postfix/main.cf
/etc/postfix/sasl_passwd
/etc/postfix/generic
/etc/aliases
/etc/passwd
Things I'm happy about:
alias
directs who gets it.[email protected]
, so it gets through the MS Online SMTP server.Things I'm not happy about:
passwd
name trick doesn't always work, and it can be difficult to figure out what server a mail is coming from.warning: smtp.mail.microsoftonline.com[65.55.171.153] offered null AUTH mechanism list
(SMTP server sends a nullAUTH
list beforeSTARTTLS
, butAUTH LOGIN
after).certificate verification failed for smtp.mail.microsoftonline.com: num=20:unable to get local issuer certificate
(There are some config options around certs, but I'm not sure if mail delivery breaks when the cert is renewed)certificate verification failed for smtp.mail.microsoftonline.com: num=27:certificate not trusted
(Same as #2)Thanks to the serverfault community for sharing strong opinions on mail servers.
You can use smtpd_sender_login_maps to specify a list of maps: sender address - user.
Example:
/etc/postfix/login-map:
It does work for sending, it should work for relaying the same way.
I use canonical mapping to rewrite the from address, such as rewriting root@app01 to [email protected].