我尝试通过 Postfix 从我的服务器发送电子邮件,但无法正常工作。我使用外部 SMTP 服务器作为中继主机。以下是相关部分/etc/postfix/main.cf
:
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
relayhost = [mail.myISP.nl]:submission
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all
smtp_generic_maps = hash:/etc/postfix/generic
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
debug_peer_list=mail.myISP.nl
debug_peer_level=5
我安装了libsasl2-2
,libsasl2-modules
和sasl2-bin
。在 中/etc/postfix/sasl_password
,我输入了有效的凭据:
[mail.myISP.nl]:587 myuserid:mypassword
之后我运行命令将文本文件转换为文件.db
:
postmap /etc/postfix/sasl_password
并重新加载 Postfix 的配置:
sudo systemctl reload postfix
但是,实际上没有发送任何邮件。我使用以下命令运行了 TCP 转储:
echo "This is a test" | mail -s "Testing" [email protected]
结果是与远程服务器进行以下交换:
(S) srv17610.myISP.nl ESMTP Exim 4.86.2 Wed, 28 Dec 2016 11:06:24 +0100
(C) EHLO hostname
(S) 250-srv17610.myISP.nl Hello my.canonical.name.nl [xxx.xxx.xxx.xxx]
(S) 250-SIZE 20971520
(S) 250-8BITMIME
(S) 250-PIPELINING
(S) 250-AUTH PLAIN LOGIN
(S) 250-STARTTLS
(S) 250 HELP
(C) MAIL FROM:<[email protected]> SIZE=310
(C) RCPT TO:<[email protected]>
(C) DATA
(S) 250 OK
(S) 550 relay not permitted, authentication required
(S) 503-All RCPT commands were rejected with this error:
(S) 503-relay not permitted, authentication required
(S) 503 Valid RCPT command must precede DATA
(C) RSET
(C) QUIT
(S) 250 Reset OK
(S) 221 srv17610.myISP.nl closing
(C) 是 Postfix,(S) 是远程服务器。您可以看到它没有发出 AUTH 命令,没有提供凭据,因此邮件被拒绝。它/var/log/mail.log
只是说邮件已发送。出了什么问题?
答案1
您的配置看起来合法,但 postfix 要求它的 smtp_sasl_password_maps 文件实际上以优化的方式存储,而不是明文。
如果你没有这样的文件
运行命令:
postmap /etc/postfix/sasl_password
将生成一个sasl_password.db
服务 Postfix 重新加载
应用更改