我们的电子邮件未送达。我们进行了一些调试,但没有发现任何问题。当我们使用简单的测试脚本发送电子邮件时,PHPMailer 报告成功,并且日志表明邮件已被接受并进行投递:
已接受消息传送
但没有任何东西到达接收端,没有到达收件箱,也没有到达垃圾邮件文件夹。
我们的调试选项有哪些?
我们已采取以下措施
- 按照以下说明安装并配置 Postfix MTA本指南
- 已在 UFW 中打开端口 25、465 和 587
- 已验证我们可以通过 telnet 连接到 Gmail SMTP(使用
telnet -4 smtp.gmail.com 25
) - 使用 PHPMailer 发送带有低级日志记录的电子邮件的脚本 (
$mail->SMTPDebug = 4;
)
以下是我们用虚拟详细信息更改了识别信息的示例日志:
2019-03-15 16:19:42 Connection: opening to localhost:25, timeout=300, options=array()
2019-03-15 16:19:42 Connection: opened
2019-03-15 16:19:42 SMTP INBOUND: "220 example.com ESMTP Sendmail 8.14.4/8.14.4/Debian-4.1ubuntu1; Fri, 15 Mar 2019 17:19:42 +0100; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]"
2019-03-15 16:19:42 SERVER -> CLIENT: 220 example.com ESMTP Sendmail 8.14.4/8.14.4/Debian-4.1ubuntu1; Fri, 15 Mar 2019 17:19:42 +0100; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
2019-03-15 16:19:42 CLIENT -> SERVER: EHLO example.com
2019-03-15 16:19:42 SMTP INBOUND: "250-example.com Hello localhost [127.0.0.1], pleased to meet you"
2019-03-15 16:19:42 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2019-03-15 16:19:42 SMTP INBOUND: "250-PIPELINING"
2019-03-15 16:19:42 SMTP INBOUND: "250-EXPN"
2019-03-15 16:19:42 SMTP INBOUND: "250-VERB"
2019-03-15 16:19:42 SMTP INBOUND: "250-8BITMIME"
2019-03-15 16:19:42 SMTP INBOUND: "250-SIZE"
2019-03-15 16:19:42 SMTP INBOUND: "250-DSN"
2019-03-15 16:19:42 SMTP INBOUND: "250-ETRN"
2019-03-15 16:19:42 SMTP INBOUND: "250-AUTH DIGEST-MD5 CRAM-MD5"
2019-03-15 16:19:42 SMTP INBOUND: "250-DELIVERBY"
2019-03-15 16:19:42 SMTP INBOUND: "250 HELP"
2019-03-15 16:19:42 SERVER -> CLIENT: 250-example.com Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
2019-03-15 16:19:42 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2019-03-15 16:19:42 SMTP INBOUND: "250 2.1.0 <[email protected]>... Sender ok"
2019-03-15 16:19:42 SERVER -> CLIENT: 250 2.1.0 <[email protected]>... Sender ok
2019-03-15 16:19:42 CLIENT -> SERVER: RCPT TO:<[email protected]>
2019-03-15 16:19:42 SMTP INBOUND: "250 2.1.5 <[email protected]>... Recipient ok
"2019-03-15 16:19:42 SERVER -> CLIENT: 250 2.1.5 <[email protected]>... Recipient ok
2019-03-15 16:19:42 CLIENT -> SERVER: DATA
2019-03-15 16:19:42 SMTP INBOUND: "354 Enter mail, end with "." on a line by itself"
2019-03-15 16:19:42 SERVER -> CLIENT: 354 Enter mail, end with "." on a line by itself
2019-03-15 16:19:42 CLIENT -> SERVER: Date: Fri, 15 Mar 2019 17:19:42 +0100
2019-03-15 16:19:42 CLIENT -> SERVER: To: [email protected]
2019-03-15 16:19:42 CLIENT -> SERVER: From: [email protected]
2019-03-15 16:19:42 CLIENT -> SERVER: Subject: Test Email
2019-03-15 16:19:42 CLIENT -> SERVER: Message-ID: <[email protected]>
2019-03-15 16:19:42 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
2019-03-15 16:19:42 CLIENT -> SERVER: MIME-Version: 1.0
2019-03-15 16:19:42 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2019-03-15 16:19:42 CLIENT -> SERVER:
2019-03-15 16:19:42 CLIENT -> SERVER: The body of the test email.
2019-03-15 16:19:42 CLIENT -> SERVER:
2019-03-15 16:19:42 CLIENT -> SERVER: .
2019-03-15 16:19:42 SMTP INBOUND: "250 2.0.0 x2FGJgcR016911 Message accepted for delivery"
2019-03-15 16:19:42 SERVER -> CLIENT: 250 2.0.0 x2FGJgcR016911 Message accepted for delivery
2019-03-15 16:19:42 CLIENT -> SERVER: QUIT
2019-03-15 16:19:42 SMTP INBOUND: "221 2.0.0 example.com closing connection"
2019-03-15 16:19:42 SERVER -> CLIENT: 221 2.0.0 example.com closing connection
2019-03-15 16:19:42 Connection: closed
更新
日志/var/log/mail.log
很长(超过 400KB),但我在其中搜索了包含以下内容的行,x2FGJgcR016911
因为它看起来像某种哈希,并且出现在上面的示例日志中。我找到了以下四行(再次掩盖了其中的识别信息):
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJgcR016911: to=<[email protected]>, delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=120332, relay=gmail-smtp-in.l.google.com. [74.125.140.26], dsn=5.0.0, stat=Service unavailable
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJgcR016911: to=<[email protected]>, delay=00:00:01, mailer=local, pri=120332, dsn=5.1.1, stat=User unknown
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJgcR016911: to=postmaster, delay=00:00:01, mailer=local, pri=120332, dsn=5.1.1, stat=User unknown
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJgcR016911: x2FGJhcR016913: postmaster notify: User unknown
更新 2
@MichaelHampton 解释的日志显示有两次退回。以下是与第二次退回相关的附加行:
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJhcR016913: to=MAILER-DAEMON, delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJhcR016913: to=postmaster, delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJhcR016913: x2FGJhcS016913: return to sender: User unknown
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJhcS016913: to=MAILER-DAEMON, delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Mar 15 17:19:43 m1-production sm-mta[16913]: x2FGJhcR016913: Saved message in /var/lib/sendmail/dead.letter
答案1
如果您使用 postfix,建议删除 sendmail
sudo apt remove --purge sendmail
或 Red Hat 家族 (CentOS、Fedora 等)
sudo yum remove sendmail
最后,如果您不想删除 sendmail,只需使用以下命令:
sudo systemctl stop sendmail
sudo systemctl disable sendmail
sudo systemctl mask --now sendmail
选项 umask 和 enable 以及 start 可以恢复状态。