如何修复 "stat=Deferred: Connection timed out error in sendmail"

在使用 MTA(sendmail) 发送邮件时遇到此错误:

stat=Deferred:sendmail中的连接超时错误

原因:

如果我们收到此错误,则表示邮件服务器很可能由于防火墙而无法连接到 smtp 提供商。
所以检查你的防火墙,如果你的服务器正在监听 smtp 端口 25、587 和 465,除非你指定了一些自定义端口号。

# netstat -ntlp | grep sendmail
tcp   0   0.0.0.0:587      0.0.0.0:*    LISTEN    1419/sendmail
tcp   0   0 0.0.0.0:465    0.0.0.0:*    LISTEN    1419/sendmail 
tcp   0   0 0.0.0.0:25     0.0.0.0:*    LISTEN    1419/sendmail

很多时候,网络防火墙可能会阻止某些特定端口,因此我们可以使用 telnet 进行检查。

解决方案:

在 sendmail.mc 文件中进行以下更改

注释掉下面显示的行,因为这将限制邮件服务器仅侦听 localhost 环回地址而没有任何其他地址

注意:在 sendmail 中,“#”不用于注释任何行。
我们需要使用“dnl”或者“dnl#”

dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

或者

我们可以将其更改为

DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

如果我们使用的是 587 端口,请取消注释此行

DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl 
and for port 465 uncomment below line
DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl 
You can use ssl ports by adding these two lines in your sendmail.mc file
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 465')dnl  Save and exit your file

更改配置后,重启sendmail服务

# m4 sendmail.mc > sendmail.cf 
# service sendmail restart

现在重新尝试连接 SMTP 服务器,因为在我的情况下它是使用端口号的 smtp.gmail.com。

# telnet smtp.gmail.com 25
Trying 74.125.127.109...
 Connected to smtp.gmail.com. 
 Escape character is '^]'. 
 220 mx.google.com ESMTP io2sm27316728pbc.24

它显示已连接,同样我们可以检查其他端口号。

日期:2020-06-02 22:17:17 来源:oir作者:oir