Joh*_*ock 46 postfix hosted-exchange
我正在尝试从我们的 AWS EC2 实例获取电子邮件报告。我们正在使用 Exchange Online(Microsoft Online Services 的一部分)。我已经设置了一个专门用于SMTP 中继的用户帐户,并且我已经设置了 Postfix 以满足通过此服务器中继消息的所有要求。但是,Exchange Online 的 SMTP 服务器将拒绝邮件,除非发件人地址与身份验证地址完全匹配(错误消息为550 5.7.1 Client does not have permissions to send as this sender
)。
通过仔细配置,我可以设置我的服务以作为该用户发送。但我不是小心谨慎的忠实粉丝 - 我宁愿让 postfix 强制解决这个问题。有没有办法做到这一点?
Jas*_*per 64
这就是如何在 postfix 中真正做到这一点。
此配置更改来自本地发起和中继的 SMTP 邮件流量的发件人地址:
/etc/postfix/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
Run Code Online (Sandbox Code Playgroud)
从来自服务器本身的电子邮件重写信封地址
/etc/postfix/sender_canonical_maps:
/.+/ newsender@address.com
Run Code Online (Sandbox Code Playgroud)
从 SMTP 中继电子邮件中的地址重写
/etc/postfix/header_check:
/From:.*/ REPLACE From: newsender@address.com
Run Code Online (Sandbox Code Playgroud)
例如,如果您使用本地中继 smtp 服务器,您的所有多功能和多个应用程序都使用该服务器,这将非常有用。
如果您使用 Office 365 SMTP 服务器,任何发件人地址与来自经过身份验证的用户本身的电子邮件不同的邮件都将被拒绝。上面的配置可以防止这种情况。
Joc*_*lyn 16
可选的通用表指定从服务器传递(发送)邮件时应用的地址映射。
这与规范映射相反,规范映射适用于服务器接收邮件时。
(注意:FROM 和 TO 地址都匹配以替换任何通用表和规范表。)
已经解释了服务器接收邮件时使用规范表是其他答案。
当邮件从服务器发送时,您可以使用smtp_generic_maps
.
根据后缀文档:
/etc/postfix/main.cf:
smtp_generic_maps = hash:/etc/postfix/generic
/etc/postfix/generic:
user@localdomain.local account@isp.example.com
@localdomain.local wholedomain@isp.example.com
Run Code Online (Sandbox Code Playgroud)
然后做:
sudo postmap /etc/postfix/generic
sudo /etc/init.d/postfix reload
Run Code Online (Sandbox Code Playgroud)
参考:
更新:根据一位 IT 朋友的建议,我在所有服务器上运行 postfix,而不是制作一个云邮件服务器。到目前为止,这是我的解决方案:
/etc/postfix/main.cf
# output of hostname -f - mail from local users appears to come from here
myhostname = domU-01-02-03-04-05-06.compute-1.internal
# Local delivery - include all 127.0.0.1 aliases from /etc/hosts
mydestination = $myhostname, $mydomain, rest_of_entries_from_hosts
# Needed for address translation to work
myorigin = $mydomain
# Talking to MS Online
# :submission = port 587
relayhost = [smtp.mail.microsoftonline.com]:submission
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = # Yes, leave empty
smtp_tls_security_level = encrypt
smtp_generic_maps = hash:/etc/postfix/generic
# Enable if you need debugging, but it does leak credentials to the log
#debug_peer_level = 2
#debug_peer_list = smtp.mail.microsoftonline.com
# Only listen on the local interfaces (not the public)
inet_interfaces = localhost
# I left out a bunch of CentOS defaults. postconf -n is your friend.
# These are included
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
Run Code Online (Sandbox Code Playgroud)
/etc/postfix/sasl_passwd
# Run postmap /etc/postfix/sasl_passwd after editing
# Also, chown root:root; chmod 600
smtp.mail.microsoftonline.com relayer@hosteddomain.com:YourP@ssw0rd
Run Code Online (Sandbox Code Playgroud)
/etc/postfix/generic
# Run postmap /etc/postfix/generic
# I've seen local mail come from either source
# output of dnsdomainname
@compute-1.internal relayer@hosteddomain.com
# output of hostname -f
@domU-01-02-03-04-05-06.compute-1.internal relayer@hosteddomain.com
Run Code Online (Sandbox Code Playgroud)
/etc/aliases
# Run newaliases after changing
# Lot of stuff here. Mostly, just make sure the graph points to root, such as
mailer-daemon: postmaster
postmaster: root
# And the important part - your email or distribution group
root: awsadmins@hosteddomain.com
Run Code Online (Sandbox Code Playgroud)
/etc/passwd
# Sometimes it helps to expand the name, so email comes from 'root at aws host 5'
# rather than just 'root'
# Was
#root:x:0:0:root:/root:/bin/bash
# Is
root:x:0:0:root on aws host 5:/root:/bin/bash
Run Code Online (Sandbox Code Playgroud)
我很高兴的事情:
alias
指示谁收到它。relayer@hosteddomain.com
,因此它会通过 MS Online SMTP 服务器。我不高兴的事情:
passwd
名招并不总是工作,它可能很难找出服务器邮件的来源。warning: smtp.mail.microsoftonline.com[65.55.171.153] offered null AUTH mechanism list
(SMTP 服务器AUTH
在 之前STARTTLS
、AUTH LOGIN
之后发送一个空列表)。certificate verification failed for smtp.mail.microsoftonline.com: num=20:unable to get local issuer certificate
(有一些关于证书的配置选项,但我不确定证书更新时邮件传递是否中断)certificate verification failed for smtp.mail.microsoftonline.com: num=27:certificate not trusted
(同#2)感谢 serverfault 社区分享对邮件服务器的强烈意见。
您可以使用smtpd_sender_login_maps指定映射列表:发件人地址 - 用户。
例子:
smtpd_sender_login_maps =
hash:/etc/postfix/login-map
Run Code Online (Sandbox Code Playgroud)
/etc/postfix/登录地图:
mail1@domain userlogin
mail2@domain userlogin, otheruser@example.com
Run Code Online (Sandbox Code Playgroud)
它确实适用于发送,它应该以同样的方式适用于中继。
归档时间: |
|
查看次数: |
79180 次 |
最近记录: |