我使用以下方式配置了 Postfix本指南。当我发送测试电子邮件时,我收到以下错误消息:
May 23 15:36:26 VM11 postfix/smtp[15321]: connect to smtp.gmail.com[2a00:1450:4001:c02::6d]:587: Network is unreachable
May 23 15:36:26 VM11 postfix/smtp[15321]: 4AA58243A3: to=<[email protected]>, relay=smtp.gmail.com[173.194.70.108]:587, delay=0.07, delays=0.01/0/0.04/0.02, dsn=5.7.0, status=bounced (host smtp.gmail.com[173.194.70.108] said: 530 5.7.0 Must issue a STARTTLS command first. y10sm16916731eev.3 - gsmtp (in reply to MAIL FROM command))
May 23 15:36:26 VM11 postfix/qmgr[15314]: 4AA58243A3: removed
我配置了我的身份验证数据:
[stmp.gmail.com]:587 USER@GOOGLEDOMAIN:PASSWORD
以下是我的一般配置main.cf
:
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
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
# 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.
myhostname = VM11.rbg.informatik.tu-darmstadt.de
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination =
relayhost = [smtp.gmail.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 51200000
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all
# Further authentication stuff
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_tls_auth_only = no
那么配置到底有什么问题呢?
编辑:根据 Andrzej A. Filip 的建议,我将smtpd_use_tls=yes
其改为smtp_use_tls
。现在,我又收到另一条错误消息:
May 26 11:20:36 VM11 postfix/smtp[20031]: D9982243B9: to=<[email protected]>, relay=smtp.gmail.com[173.194.70.108]:587, delay=0.19, delays=0.02/0/0.15/0.01, dsn=5.5.1, status=bounced (host smtp.gmail.com[173.194.70.108] said: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 z52sm34463651eea.1 - gsmtp (in reply to MAIL FROM command))
我仔细检查了我的 sasl_password 文件并再次对其进行了 postmap,但没有成功。
答案1
尝试以下操作修改版本这在 Ubuntu 18.04 中对我有用(假设从头开始,vi
用nano
或任何你熟悉的编辑器替换):
以 root 身份完成这些步骤。
apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
注意:如果终端提示问题,请选择“互联网站点”和其他默认选项。dpkg-reconfigure postfix
如果需要重新配置 postfix,请运行。- 使用以下方式创建密码文件
vi /etc/postfix/sasl_passwd
- 填充密码文件。例如:
[smtp.gmail.com]:587 [email protected]:mypassword
- 通过运行来保护文件
chmod 600 /etc/postfix/sasl_passwd
- 代替通过运行配置文件的内容
vi /etc/postfix/main.cf
将以下内容放入文件中:
relayhost = [smtp.gmail.com]:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_security_options = smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
通过运行对密码文件进行编码
postmap /etc/postfix/sasl_passwd
postfix
通过运行重新启动服务systemctl restart postfix.service
[email protected]
将以下代码替换为您的电子邮件并测试发送邮件:echo "Test mail from postfix" | mail -s "Test Postfix" [email protected]
给 Google 一分钟时间处理。您应该会在 Gmail 帐户的已发送文件夹中以及指定目标帐户的收件箱中看到已发送的邮件。如果邮件未到达,请检查
cat /var/mail/root
或cat /var/log/mail.log
其他地方取决于您的分布查找错误。
答案2
菜谱上提到smtp_use_tls
但您已设置smtpd_use_tls
。
http://mhawthorne.net/posts/postfix-configuring-gmail-as-relay.html
故障排除 / 1. 没有 TLS
答案3
除了 Andrzej A. Filip 的观察外,密码文件还包含一个拼写错误:
stmp.gmail.com
应该smtp.gmail.com