Sendmail 将邮件排队,但不发送

Sendmail 将邮件排队,但不发送

我有一个装有 php 和 sendmail 的 Ubuntu 服务器。

当我使用 PHP 通过 sendmail 发送电子邮件时,邮件会永远停留在 sendmail 队列中,永远不会被发送。即使我强制刷新它,它仍然停留在队列中。

这可能是什么原因造成的?我该如何解决?

谢谢。

编辑:“cat /var/spool/mqueue/qfn82FuSu3009905”的输出是:

V8
T1251906988
K1251927546
N6
P570369
I8/1/121795
MDeferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Fwbs
$_localhost [127.0.0.1]
$rESMTP
$sworld0.com
${daemon_flags}
${if_addr}127.0.0.1
S<[email protected]>
A<>
MDeferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
rRFC822; [email protected]
RPFD:<[email protected]>
H?P?Return-Path: <g>
H??Received: from world0.com (localhost [127.0.0.1])
    by world0.com (8.14.3/8.14.3/Debian-6) with ESMTP id n82FuSu3009905
    for <[email protected]>; Wed, 2 Sep 2009 08:56:28 -0700
H?x?Full-Name: www-data
H??Received: (from www-data@localhost)
    by world0.com (8.14.3/8.14.3/Submit) id n82FuR5T009904;
    Wed, 2 Sep 2009 08:56:27 -0700
H??Date: Wed, 2 Sep 2009 08:56:27 -0700
H??Message-Id: <[email protected]>
H??To: [email protected]
H??Subject: Website feedback form
H??MIME=Version: 1.0
H??Content-type: text/html; charset=iso-8859-1
H??From: [email protected]
.

我不知道哪里出了问题。

编辑2:

嗯,我可以 ping 通服务器,但不能通过 telnet 与服务器通信,这是怎么回事?我没有运行防火墙。

root@world0:~# telnet alt4.gmail-smtp-in.l.google.com 25
Trying 72.14.221.114...
telnet: Unable to connect to remote host: Connection timed out
root@world0:~# ping 72.14.221.114
PING 72.14.221.114 (72.14.221.114) 56(84) bytes of data.
64 bytes from 72.14.221.114: icmp_seq=1 ttl=241 time=167 ms
64 bytes from 72.14.221.114: icmp_seq=2 ttl=241 time=171 ms
64 bytes from 72.14.221.114: icmp_seq=3 ttl=241 time=169 ms
64 bytes from 72.14.221.114: icmp_seq=4 ttl=241 time=222 ms
^C
--- 72.14.221.114 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3015ms
rtt min/avg/max/mdev = 167.840/182.722/222.589/23.055 ms

答案1

要了解有关消息配置的更多信息,请尝试以下操作:

mailq

你会看到很多这样的行:

n812uLGQ001861 12089700 Mon Aug 31 19:56 <******@*****.org>
                 (Deferred: Connection timed out with c.mx.mail.yahoo.com.)
                                         <******@yahoo.com>
n82FR6a3019167 22388400 Wed Sep  2 08:27 <******@*****.net>
                 (reply: read error from g.mx.mail.yahoo.com.)
                                         <******@yahoo.com>

在哪里n82FR6a3019167是消息 ID

ls -al /var/spool/mqueue/*<message ID>

尝试查看这些文件(它们只是文本文件),特别是名为qn82FR6a3019167(或者您的消息 ID 号码。 注意:'' 在消息 ID 之前。您应该能够确定消息的状态,这有望帮助确定哪些部分无法正常工作。

cat /var/spool/mqueue/qn82FR6a3019167

如果这没有帮助,您可能需要查看 sendmail.cf 中的智能中继设置。您的 PHP 服务器可能需要通过智能中继主机


接下来我会尝试手动 SMTP 会话从您的 PHP 服务器到 Google 邮件服务器。

telnet alt4.gmail-smtp-in.l.google.com 25

Trying 209.85.129.114...
Connected to alt4.gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP p9si790839fkb.7

helo <yourhostname>
250 mx.google.com at your service

mail from:<[email protected]>
250 2.1.0 OK p9si740839fkb.7

rcpt to:<[email protected]>
250 2.1.5 OK p9si740839fkb.7

data
354  Go ahead h2si759562fkh.29
Subject: This is a test

Testing!
.
250 2.0.0 OK 1251933071 h2si759562fkh.29
quit

221 2.0.0 closing connection h2si759562fkh.29

Connection closed by foreign host.

这将告诉您您的 IP 地址是否被阻止,或者是否存在某些 SPF(发件人策略框架)问题,或者您的 DNS 名称是否不匹配,这可能导致您的电子邮件被拒绝或延迟。

我猜想您在回复中删减了详细信息列表。您的系统确实应该有一个有效的主机名,并且该主机名有反向 DNS 条目。

另外,请检查您的 /etc/hosts 文件,确保您的 IP 地址在此处正确列出。在将电子邮件转发到互联网时,主机名不匹配是一个很常见的问题(至少,根据我的经验)。

就像是:

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1        localhost.localdomain localhost
xxx.xxx.xxx.xxx  yourhostname.yourdomain.com yourhostname

答案2

我找到了解决方案。

我的 ISP 开始默认阻止端口 25 以阻止垃圾邮件发送者。给他们打了个电话,端口就重新打开了,所有邮件都开始流动了。

谢谢乔的帮助。

答案3

查看显示 的行Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com。它们告诉您,您的服务器能够解析 gmail.com 的 MX 记录,但无法连接到远程服务器。当您从邮件服务器 telnet 到该主机上的端口 25 时会发生什么?您应该看到类似这样的内容(请注意,我输入的是“quit”):

crunch:/Users/gerald$ telnet alt4.gmail-smtp-in.l.google.com 25
Trying 72.14.221.114...
Connected to alt4.gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP d4si791296fga.25
quit
221 2.0.0 closing connection d4si791296fga.25
Connection closed by foreign host.

您是否已设置任何防火墙规则来阻止端口 25 上的出站连接?

答案4

首先检查队列中的消息和错误日志(/var/log/mail.err),然后为了强制删除,你可以这样做(即使它真的卡住了)

rm -rf /var/spool/mqueue/*

相关内容