我目前正在尝试在 CentOS 6.4 机器上使用 Postfix 设置到 Gmail 的 SMTP 中继服务器,以便我可以从我的 PHP 脚本发送电子邮件。
我跟着这教程,但我尝试执行时收到此错误输出
发送邮件[电子邮件保护]
输出:
tail -f /var/log/maillog
Apr 16 01:25:54 ext-server-dev01 postfix/cleanup[3646]: 86C2D3C05B0: message-id=<[email protected]>
Apr 16 01:25:54 ext-server-dev01 postfix/qmgr[3643]: 86C2D3C05B0: from=<[email protected]>, size=297, nrcpt=1 (queue active)
Apr 16 01:25:56 ext-server-dev01 postfix/smtp[3648]: 86C2D3C05B0: to=<[email protected]>, relay=smtp.gmail.com[173.194.79.108]:587, delay=4.8, delays=3.1/0.04/1.5/0.23, dsn=5.5.1, status=bounced (host smtp.gmail.com[173.194.79.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 qh4sm3305629pac.8 - gsmtp (in reply to MAIL FROM command))
这是我的主配置文件配置,我尝试了许多不同的选项,但似乎没有任何效果:
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = localhost
inet_protocols = ipv4
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost
myhostname = host.local.domain
myorigin = $myhostname
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relayhost = [smtp.gmail.com]:587
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_type = cyrus
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_use_tls = yes
smtpd_sasl_path = smtpd
unknown_local_recipient_reject_code = 550
在里面在 /etc/postfix/sasl_passwd 文件中文件(sasl_passwd 和 sasl_passwd.db)我得到以下内容(删除了真实密码,并将其替换为“密码”):
[smtp.google.com]:587[电子邮件保护]:密码
要创建 sasl_passwd.db 文件,我通过运行以下命令来完成:
postmap 哈希:/etc/postfix/sasl_passwd
有人知道为什么我似乎无法从服务器发送电子邮件吗?
亲切问候 Alex
答案1
# telnet smtp.gmail.com 587
Trying 173.194.70.108...
Connected to smtp.gmail.com.
Escape character is '^]'.
220 mx.google.com ESMTP h52sm28987766eez.3 - gsmtp
ehlo localhost
250-mx.google.com at your service, [46.4.15.52]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 CHUNKING
没有可用的身份验证。您必须使用启动TLS在端口 25/587 上或在端口 465 上使用 SSL/TLS
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
smtp_tls_security_level = secure
smtp_tls_mandatory_protocols = TLSv1
smtp_tls_mandatory_ciphers = high
smtp_tls_secure_cert_match = nexthop
在 /etc/postfix/tls_policy 中
gmail.com encrypt protocols=TLSv1 ciphers=high
在 /etc/postfix/sasl_passwd 文件中
[smtp.gmail.com]:587 [email protected]:password
在邮件日志中会有类似以下内容
# swaks -s 127.0.0.1 --helo localhost --to [email protected] --from [email protected]
# cat /var/log/maillog | grep 283AC120834
Sep 21 15:43:55 mail postfix/smtpd[28486]: 283AC120834: client=localhost[127.0.0.1]
Sep 21 15:43:55 mail postfix/cleanup[28489]: 283AC120834: message-id=<[email protected]>
Sep 21 15:43:55 mail postfix/qmgr[28481]: 283AC120834: from=<[email protected]>, size=449, nrcpt=1 (queue active)
Sep 21 15:43:56 mail postfix/smtp[28490]: 283AC120834: to=<[email protected]>, relay=smtp.gmail.com[173.194.70.108]:587, delay=1.7, delays=0.01/0/0.64/1, dsn=2.0.0, status=sent (250 2.0.0 OK 1379792594 y47sm29107298eew.12 - gsmtp)
Sep 21 15:43:56 mail postfix/qmgr[28481]: 283AC120834: removed