我花了几天的时间去研究SO问题和Postfix文档,但没有成功地弄清楚我做错了什么。 我的情况如下:
版本信息:Debian 7上的Postfix 2.11.2(Wheezy)
输出postconf -n:
alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases append_at_myorigin = no append_dot_mydomain = no biff = no canonical_maps = regexp:/etc/postfix/canonical canonical_classes = envelope_sender, header_sender config_directory = /etc/postfix inet_interfaces = localhost inet_protocols = ipv4 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 mydestination = localhost.com, localhost myhostname = DomainA.com mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 myorigin = /etc/mailname readme_directory = no recipient_delimiter = + sender_dependent_relayhost_maps = hash:/etc/postfix/relayhost_map smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_sender_dependent_authentication = yes smtp_tls_note_starttls_offer = yes smtp_tls_security_level = may smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key smtpd_tls_security_level = may smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtpd_use_tls = yes
relayhost_map文件的内容:
@DomainA.com [smtp.mailgun.org]:587 @DomainB.name [smtp.mailgun.org]:587
尝试#canonical_maps- 所有电子邮件地址重写到[email protected]
/./ [email protected]
从命令行发送邮件时输出mail.log:
Aug 18 01:55:12 DomainA postfix/pickup[3572]: C72492A00B8: uid=0 from=<root> Aug 18 01:55:12 DomainA postfix/cleanup[3591]: C72492A00B8: message-id=<[email protected]> Aug 18 01:55:12 DomainA postfix/qmgr[3573]: C72492A00B8: from=<[email protected]>, size=437, nrcpt=1 (queue active) Aug 18 01:55:13 DomainA postfix/smtp[3593]: C72492A00B8: to=<[email protected]>, relay=smtp.mailgun.org[50.56.21.178]:587, delay=0.28, delays=0.02/0.02/0.16/0.08, dsn=2.0.0, status=sent (250 Great success)
通过邮件客户端收到电子邮件标题:
Delivered-To: [email protected] Return-Path: <[email protected]> [snip] Sender: [email protected] [snip] From: Primary Root <[email protected]> To: [email protected] Subject: test mail #5
有两件事对我来说是非常错误的:
为什么发件人地址设置为post = [email protected],即使Postfix设置为:
append_at_myorigin = no append_dot_mydomain = no
由于发件人地址附加了DomainA.com,所以Postfixselect使用SAS的SASL详细信息中继邮件 – 通过查看MailGun仪表板上的日志进行确认。 这导致反弹地址也被设置为DomainA。
尝试canoncial_maps#2, 只有以DomainB.com结尾的电子邮件地址被重新写入[email protected]
/@DomainB.name/ [email protected]
.muttrc文件设置强制从电子邮件地址作为DomainB.com
set from="[email protected]" set use_from=yes set use_envelope_from = yes
mail.log的输出:
Aug 18 03:40:49 DomainA postfix/qmgr[8809]: 2BEB92A00D3: from=<[email protected]>, size=441, nrcpt=1 (queue active) Aug 18 03:40:49 DomainA postfix/smtp[8824]: 2BEB92A00D3: to=<[email protected]>, relay=smtp.mailgun.org[104.130.177.23]:587, delay=0.58, delays=0.01/0.02/0.37/0.17, dsn=2.0.0, status=sent (250 Great success)
通过邮件客户端收到电子邮件标题:
Delivered-To: [email protected] [snip] Return-Path: <[email protected]> [snip] Sender: [email protected] [snip] From: Primary Root <[email protected]> To: [email protected] Subject: test mail hdr #7
任何关于如何解决这个问题的build议/想法是最受欢迎的!
为了对这个问题有一个全新的认识,我开始在另一台服务器上configuration一个类似的中继主机设置,在这个过程中,我终于find了问题的根源。 在我的sasl_passwd文件中发现我缺less一个关键字符。
解决之前的sasl_passwd文件:
DomainB.name [email protected]:somepassword #Fallback [smtp.mailgun.org]:587 [email protected]:anotherpasswd
解决之后的sasl_passwd文件:
@DomainB.name [email protected]:somepassword #Fallback [smtp.mailgun.org]:587 [email protected]:anotherpasswd
问题是虚拟DomainB之前的单个缺less“@”字符。 后备条目是为什么事实certificate如此难以debugging的问题,因为当Postfix无法匹配任何其他条目时,所有邮件都通过此路由传递。
因为它可能certificate是有用的,所以一旦我的relayhostconfiguration开始正常工作,我还包括我的规范映射文件的设置:
/(.*@)DomainB.name/ ${1}DomainB.name /(.*@)DomainA.com/ ${1}DomainA.com
上面的正则expression式确保信封发送者被更新以匹配来自发件人,避免在我的电子邮件客户端中的任何“通过DomainA”。
作为后记,事实certificate,在Ubuntu 14.04中main.cf中只有以下几行是不够的:
canonical_maps = regexp:/etc/postfix/canonical canonical_classes = envelope_sender, header_sender
还必须包含以下行:
sender_canonical_maps = regexp:/etc/postfix/canonical_sender
第二个文件的内容可能与第一个文件相同,但在Ubuntu中继电子邮件时,它必须存在才能避免“通过域”标头。