使用 Gmail 作为中继主机时出现 Postfix tls 错误

使用 Gmail 作为中继主机时出现 Postfix tls 错误

在配置 php 联系表单时,我遇到了一个奇怪的问题,即 postfix 拒绝发送电子邮件,我已将错误范围缩小到一个,偶尔是第二个。

第一个是:

来自 /var/log/maillog

 connect to smtp.gmail.com[2607:f8b0:400d:c03::6c]:587: Network is unreachable
Jun 11 16:57:59 site postfix/smtp[1315]: E79467A7: to=<apache@site.[domain].com>, relay=smtp.gmail.com[173.194.205.109]:587, delay=0.19, delays=0.01/0/0.16/0.02, dsn=5.5.1, status=bounced (host smtp.gmail.com[173.194.205.109] said: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1  https://support.google.com/mail/?p=WantAuthError y131-v6sm20355089qka.30 - gsmtp (in reply to MAIL FROM command))

按照错误日志中的建议,启用了“允许安全性较低的应用程序”,并且我在 main.cf 中添加了 tls 支持

main.cf 转储

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
#myhostname = [site].[domain].com
#mydomain = [domain].com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
#mynetworks = <192.168.122.0/24, 192.168.100.0/24, 127.0.0.0/8>
relayhost = [smtp.gmail.com]:587
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases


debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/pki/tls/cert.pem

我不熟悉 postfix,不知道它的工作原理,也不知道它需要什么。如能得到任何帮助,我将不胜感激。

答案1

至于第一条消息:

connect to smtp.gmail.com[2607:f8b0:400d:c03::6c]:587: Network is unreachable

这意味着您的服务器的网络配置不允许 postfix 到达 IPv6 地址,但您将 postfix 配置为尝试使用 IPv6。

您应该检查您的主机配置,如果您无法访问 IPv6 网络,请在 Postfix 中禁用 ipv6 处理:

postconf -e inet_protocols=ipv4

至于第二点:

Jun 11 16:57:59 site postfix/smtp[1315]: E79467A7: to=<apache@site.[domain].com>, relay=smtp.gmail.com[173.194.205.109]:587, delay=0.19, delays=0.01/0/0.16/0.02, dsn=5.5.1, status=bounced (host smtp.gmail.com[173.194.205.109] said: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1  https://support.google.com/mail/?p=WantAuthError y131-v6sm20355089qka.30 - gsmtp (in reply to MAIL FROM command))

该消息可以读如下:

  • relay=smtp.gmail.com[173.194.205.109]:587, delay=0.19, delays=0.01/0/0.16/0.02
    • Postfix 将邮件发送到指定的中继主机
  • dsn=5.5.1, status=bounced
    • 主人拒绝处理该消息
  • host smtp.gmail.com[173.194.205.109] said: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/?p=WantAuthError y131-v6sm20355089qka.30 - gsmtp (in reply to MAIL FROM command)
    • 这是您使用的中继主机发送的拒绝解释。在这种情况下,这是 Google 的说法,表示您没有发送登录名/密码来在中继上进行身份验证,或者使用的登录名/密码不正确。

进一步解释/帮助您了解内容/etc/postfix/sasl_passwd将会/etc/postfix/tls_policy很有用。

/etc/postfix/sasl_passwd应该包含这样的一行

smtp.gmail.com <gmail-accound-username>:<gmail-password>

答案2

关于第一个错误我确实同意 silmaril 的观点。

您已为 postfix 启用 IPv6,但是系统上未配置 v6 网络,或者防火墙阻止了 v6 连接smtp.gmail.com

关于第二个问题我猜你在配置 postfix 以使用 Gmail SMTP 作为中继时可能忘记运行以下命令:

sudo postmap /etc/postfix/sasl_passwd

相关内容