我正在配置一个新的 Ubuntu 服务器 (18.04 LTS),作为内部主机发送邮件的邮件中继,用于在设备出现问题时发送通知电子邮件等。我们使用 Office 365,因此这使我们能够将这些类型的消息从内部设备和软件汇集到我们的邮箱。我的组织多年来一直使用 Postfix 非常简单地设置它。不幸的是,设置它的员工早已离职,我找不到有关具体细节的任何文档。但是,根据我找到的一些信息,配置似乎不需要那么复杂。我已经在新系统上安装了 Postfix,并尝试将其配置为尽可能匹配现有配置。这是我的/etc/postfix/main.cf
文件,其中包含要匿名的更改:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = myservername.domain.edu
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = myservername.domain.edu, localhost.domain.edu, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
message_size_limit = 10240000
permit_mynetworks = yes
mynetworks = 172.16.4.0/24, 172.16.5.0/24, 172.16.246.0/24, 192.168.90.0/24, 192.168.1.0/24, ###.###.103.0/24, ###.###.104.0/24, ###.###.106.0/24, ###.###.250.0/24, 10.19.64.0/27, 10.19.66.0/27, 10.19.68.0/27
我可以从这个新服务器连接到互联网,可以 ping 互联网上的资源等,但它没有发送邮件。我不断看到有关邮件被延迟和连接超时的日志条目。这是我的/var/log/mail.log
文件的最后 30 行,因此您可以看到我看到的消息类型。再次,我已将内容匿名化:
user@myservername:~$ tail -30 /var/log/mail.log
May 29 14:23:49 myservername postfix/smtp[3351]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:24:19 myservername postfix/smtp[3349]: connect to subdomain.domain.edu[###.###.104.118]:25: Connection timed out
May 29 14:24:19 myservername postfix/smtp[3350]: connect to mxa-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.104.154]:25: Connection timed out
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.104.57]:25: Connection refused
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.103.6]:25: Connection refused
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.250.72]:25: Connection refused
May 29 14:24:49 myservername postfix/smtp[3350]: connect to mxb-00246402.gslb.pphosted.com[148.163.143.147]:25: Connection timed out
May 29 14:24:49 myservername postfix/smtp[3349]: connect to subdomain.domain.edu[###.###.103.43]:25: Connection timed out
May 29 14:24:49 myservername postfix/bounce[3357]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:24:49 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.103.43]:25: Connection timed out
May 29 14:24:49 myservername postfix/bounce[3358]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:24:49 myservername postfix/smtp[3350]: 35A96120180: to=<[email protected]>, relay=none, delay=631, delays=571/0.03/60/0, dsn=4.4.1, status=deferred (connect to mxb-00246402.gslb.pphosted.com[148.163.143.147]:25: Connection timed out)
May 29 14:24:49 myservername postfix/smtp[3351]: 4047E12083C: to=<[email protected]>, relay=none, delay=431116, delays=431056/0.04/60/0, dsn=4.4.1, status=deferred (connect to subdomain.domain.edu[###.###.103.43]:25: Connection timed out)
May 29 14:25:19 myservername postfix/smtp[3349]: connect to subdomain.domain.edu[###.###.104.154]:25: Connection timed out
May 29 14:25:19 myservername postfix/smtp[3349]: 68665120733: to=<[email protected]>, relay=none, delay=434852, delays=434761/0.06/90/0, dsn=4.4.1, status=deferred (connect to subdomain.domain.edu[###.###.104.154]:25: Connection timed out)
May 29 14:25:19 myservername postfix/qmgr[1688]: 68665120733: from=<[email protected]>, status=expired, returned to sender
May 29 14:25:19 myservername postfix/cleanup[3365]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:25:19 myservername postfix/cleanup[3365]: CE1B8124492: message-id=<[email protected]>
May 29 14:25:19 myservername postfix/bounce[3357]: 68665120733: sender non-delivery notification: CE1B8124492
May 29 14:25:19 myservername postfix/qmgr[1688]: CE1B8124492: from=<>, size=2844, nrcpt=1 (queue active)
May 29 14:25:19 myservername postfix/qmgr[1688]: 68665120733: removed
May 29 14:25:49 myservername postfix/smtp[3350]: connect to mxa-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out
May 29 14:26:19 myservername postfix/smtp[3350]: connect to mxb-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out
May 29 14:26:19 myservername postfix/smtp[3350]: CE1B8124492: to=<[email protected]>, relay=none, delay=60, delays=0.03/0/60/0, dsn=4.4.1, status=deferred (connect to mxb-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out)
May 29 14:28:49 myservername postfix/qmgr[1688]: 8F7B51200D6: from=<>, size=2838, nrcpt=1 (queue active)
May 29 14:28:49 myservername postfix/trivial-rewrite[3378]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:28:49 myservername postfix/qmgr[1688]: 92033120E39: from=<>, size=2836, nrcpt=1 (queue active)
May 29 14:28:49 myservername postfix/smtp[3379]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:28:49 myservername postfix/smtp[3380]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
主机本身没有配置或运行防火墙,根据我与网络工程师的对话,应该没有任何东西阻止此流量。但是,从现有服务器,我可以通过端口 25 远程登录到我组织的 MX 记录中列出的 Office 365 邮件服务器名称,并获得响应,向其发送“helo”等。我无法从这台新服务器执行相同操作。我的网络工程师确信防火墙上没有任何东西会阻止传出流量,虽然他一直在尝试帮助我排除故障,但他没有看到任何可以表明是什么原因造成的。我不确定我还遗漏了什么。任何帮助都将不胜感激。
答案1
为了配置 SMTP 中继,您必须定义中继主机以及一些 sasl 身份验证项。
您想将这些配置项添加到main.cf 的末尾吗?
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
relayhost = your.office365.relayhost
smtp_tls_security_level = may
显然,您必须将“your.office365.relayhost”更改为真实主机名(应[smtp.office365.com]:587
根据此链接):https://secopsmonkey.com/mail-relaying-postfix-through-office-365.html
文件 sasl_password 也在链接的教程中进行了解释,它看起来应该是这样的
[smtp.office365.com]:587 [email protected]:soopersekretPassvv0rd
然后你需要用 来对它进行 postmap postmap hash:/etc/postfix/sasl_passwd
。之后你需要用 来重启 postfix systemctl restart postfix.service
。
我不熟悉 Office 365,但对于通过 MS Exchange 服务器进行中继,通常需要尝试不同的端口。
希望这可以帮助!