故事是这样的:我有 20 台 CentOS 6.9 虚拟机,通过 VHD 上传迁移到 Microsoft 的 Azure 云。部署后,我发现 Azure 不允许直接从 VM 发送电子邮件 - 我应该使用外部中继。Microsoft 似乎建议使用 Sendgrid,他们有一个免费套餐,所以我注册了,并根据他们的说明配置了 Postfix(见下文),但……什么都没有。我无法让 Postfix 与中继 SMTP 服务器或任何其他外部中继进行身份验证,例如我自己的 gzo.com 服务器(cPanel 上的 exim)或 aruba.it(一家意大利托管服务提供商)。
我使用所有这些中继对端口 587、2525 和 465 进行了各种尝试,每次都对 SASL 密码文件进行 postmap-ping 并重新启动 Postfix,但都失败并出现以下错误:
Mar 14 11:17:34 Riprid postfix/postfix-script[6664]: stopping the Postfix mail system
Mar 14 11:17:34 Riprid postfix/master[60718]: terminating on signal 15
Mar 14 11:17:34 Riprid postfix/postfix-script[6736]: starting the Postfix mail system
Mar 14 11:17:34 Riprid postfix/master[6737]: daemon started -- version 2.6.6, configuration /etc/postfix
Mar 14 11:20:00 Riprid postfix/pickup[6739]: 90887634B3: uid=0 from=<root>
Mar 14 11:20:00 Riprid postfix/cleanup[6914]: 90887634B3: message-id=<[email protected]>
Mar 14 11:20:00 Riprid postfix/qmgr[6740]: 90887634B3: from=<[email protected]>, size=437, nrcpt=1 (queue active)
Mar 14 11:20:02 Riprid postfix/smtp[6916]: warning: SASL authentication failure: No worthy mechs found
Mar 14 11:20:02 Riprid postfix/smtp[6916]: 90887634B3: SASL authentication failed; cannot authenticate to server smtp.sendgrid.net[161.202.148.160]: no mechanism available
Mar 14 11:20:03 Riprid postfix/smtp[6916]: warning: SASL authentication failure: No worthy mechs found
Mar 14 11:20:03 Riprid postfix/smtp[6916]: 90887634B3: to=<[email protected]>, relay=smtp.sendgrid.net[169.38.103.39]:587, delay=3.2, delays=0.06/0.03/3.1/0, dsn=4.7.0, status=deferred (SASL authentication failed; cannot authenticate to server smtp.sendgrid.net[169.38.103.39]: no mechanism available)
用户凭证是正确的:我确实设法通过 telnet 从 Linux shell 连接到所有三个服务器,打开 SMTP 会话,通过 AUTH PLAIN 和 AUTH LOGIN 成功验证,并手动向自己发送测试消息。只是 Postfix 无法做到这一点。
更令人困惑的是:我将完全相同的配置复制到了云中虚拟机的原始虚拟机(内部 Hyper-V),它们通过相同的服务器连接并发送邮件,没有任何错误。除了在 Azure 上运行所需的修改外,Azure 上的机器与本地的机器完全相同微软列出的。
我在谷歌上搜索到了很多建议,我都试过了,但都没有效果。我的想法(和时间)都用完了。请提出建议:我还应该去哪里找?我还能尝试什么?
这是配置(用户和密码隐藏):
[root@Riprid zeta]# uname -a
Linux Riprid 2.6.32-696.20.1.el6.centos.plus.x86_64 #1 SMP Sun Jan 28 07:56:00 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@Riprid zeta]# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
header_size_limit = 4096000
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mynetworks_style = host
newaliases_path = /usr/bin/newaliases.postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relayhost = [smtp.sendgrid.net]:587
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_generic_maps = hash:/etc/postfix/generic
smtp_sasl_auth_enable = yes
smtp_sasl_mechanism_filter = plain, login
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_tls_CAfile = /etc/postfix/gd_bundle-g2-g1.crt
smtp_tls_security_level = may
smtpd_sasl_security_options = noanonymous
smtpd_sasl_tls_security_options = noanonymous
smtpd_tls_auth_only = no
unknown_local_recipient_reject_code = 550
[root@Riprid zeta]# cat /etc/postfix/sasl_passwd
[smtp.sendgrid.net]:587 azure_260************[email protected]:OL***0***w**
[root@Riprid zeta]# cat /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
[root@Riprid zeta]# service saslauthd status
saslauthd (pid 28917) is running...
[root@Riprid zeta]# postconf -A
cyrus
[root@Riprid zeta]# yum list postfix cyrus*
...
Installed Packages
cyrus-sasl.x86_64 2.1.23-15.el6_6.2 @updates
cyrus-sasl-devel.x86_64 2.1.23-15.el6_6.2 @updates
cyrus-sasl-lib.x86_64 2.1.23-15.el6_6.2 @updates
cyrus-sasl-md5.x86_64 2.1.23-15.el6_6.2 @base
cyrus-sasl-ntlm.x86_64 2.1.23-15.el6_6.2 @base
cyrus-sasl-plain.x86_64 2.1.23-15.el6_6.2 @base
postfix.x86_64 2:2.6.6-8.el6.centos.plus @centosplus
最后,这是 saslfinger 的输出:
[root@Riprid zeta]# saslfinger -c
saslfinger - postfix Cyrus sasl configuration Wed Mar 14 11:17:38 CET 2018
version: 1.0.2
mode: client-side SMTP AUTH
-- basics --
Postfix: 2.6.6
System: CentOS release 6.9 (Final)
-- smtp is linked to --
libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x00007f79ea3db000)
-- active SMTP AUTH and TLS parameters for smtp --
relayhost = [smtp.sendgrid.net]:587
smtp_sasl_auth_enable = yes
smtp_sasl_mechanism_filter = plain, login
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_tls_CAfile = /etc/postfix/gd_bundle-g2-g1.crt
smtp_tls_security_level = may
-- listing of /usr/lib64/sasl2 --
total 640
drwxr-xr-x. 2 root root 4096 Mar 12 22:49 .
dr-xr-xr-x. 68 root root 45056 Mar 14 03:25 ..
-rwxr-xr-x. 1 root root 18776 Mar 25 2015 libanonymous.so
-rwxr-xr-x. 1 root root 18776 Mar 25 2015 libanonymous.so.2
-rwxr-xr-x. 1 root root 18776 Mar 25 2015 libanonymous.so.2.0.23
-rwxr-xr-x. 1 root root 22936 Mar 25 2015 libcrammd5.so
-rwxr-xr-x. 1 root root 22936 Mar 25 2015 libcrammd5.so.2
-rwxr-xr-x. 1 root root 22936 Mar 25 2015 libcrammd5.so.2.0.23
-rwxr-xr-x. 1 root root 52088 Mar 25 2015 libdigestmd5.so
-rwxr-xr-x. 1 root root 52088 Mar 25 2015 libdigestmd5.so.2
-rwxr-xr-x. 1 root root 52088 Mar 25 2015 libdigestmd5.so.2.0.23
-rwxr-xr-x. 1 root root 18808 Mar 25 2015 liblogin.so
-rwxr-xr-x. 1 root root 18808 Mar 25 2015 liblogin.so.2
-rwxr-xr-x. 1 root root 18808 Mar 25 2015 liblogin.so.2.0.23
-rwxr-xr-x. 1 root root 35376 Mar 25 2015 libntlm.so
-rwxr-xr-x. 1 root root 35376 Mar 25 2015 libntlm.so.2
-rwxr-xr-x. 1 root root 35376 Mar 25 2015 libntlm.so.2.0.23
-rwxr-xr-x. 1 root root 18808 Mar 25 2015 libplain.so
-rwxr-xr-x. 1 root root 18808 Mar 25 2015 libplain.so.2
-rwxr-xr-x. 1 root root 18808 Mar 25 2015 libplain.so.2.0.23
-rwxr-xr-x. 1 root root 22784 Mar 25 2015 libsasldb.so
-rwxr-xr-x. 1 root root 22784 Mar 25 2015 libsasldb.so.2
-rwxr-xr-x. 1 root root 22784 Mar 25 2015 libsasldb.so.2.0.23
-- listing of /etc/sasl2 --
total 20
drwxr-xr-x. 2 root root 4096 Sep 19 15:39 .
drwxr-xr-x. 110 root root 12288 Mar 14 03:23 ..
-rw-r--r--. 1 root root 49 Feb 21 16:39 smtpd.conf
-- permissions for /etc/postfix/sasl_passwd --
-rw-------. 1 root root 90 Mar 14 11:17 /etc/postfix/sasl_passwd
-- permissions for /etc/postfix/sasl_passwd.db --
-rw-------. 1 root root 12288 Mar 14 11:17 /etc/postfix/sasl_passwd.db
/etc/postfix/sasl_passwd.db is up to date.
-- active services in /etc/postfix/master.cf --
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
smtp inet n - n - - smtpd
pickup fifo n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr fifo n - n 300 1 qmgr
tlsmgr unix - - n 1000? 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - n - - smtp
relay unix - - n - - smtp
-o smtp_fallback_relay=
showq unix n - n - - showq
error unix - - n - - error
retry unix - - n - - error
discard unix - - n - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
-- mechanisms on [smtp.sendgrid.net]:587 --
-- end of saslfinger output --
答案1
我在使用 Red Hat Enterprise Linux Server 版本 6.9(Santiago)时也遇到了同样的问题,该问题与缺少 rpm 库有关(cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64),安装后我已修复该问题。
请检查您的系统中是否正确安装了以下所有 rpm,以避免出现 SASL 身份验证的其他问题:
cyrus-sasl-gssapi-2.1.23-15.el6_6.2.x86_64 cyrus-sasl-2.1.23-15.el6_6.2.x86_64 cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64 cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64