我正在使用 Symfony + SwiftMailer 并从 SwiftMailer 收到以下错误:
500 | Internal Server Error | Swift_TransportException
Expected response code 220 but got code "", with message ""
并且无法弄清楚为什么。我在我的本地机器上使用 hMailServer,并设置了我的 factory.yml 文件(因为我正在使用 Symfony),如下所示:
mailer:
class: sfMailer
param:
logging: %SF_LOGGING_ENABLED%
charset: %SF_CHARSET%
delivery_strategy: realtime
transport:
class: Swift_SmtpTransport
param:
host: splodge.loc
port: 25
encryption: ~
username: ~
password: ~
我正在使用以下代码发送:
$message = $this->getMailer()->compose(
'noreply@splodge.loc',
'info@splodge.loc',
'Reset Password',
'Message'
);
$result = $this->getMailer()->send($message);
以前有人遇到过这样的问题吗?
我发现有时,并且非常随机地发送通过,但每隔一次,我都会收到上述错误消息。因此,不断刷新发送邮件的页面,意外失败,并且由于代码有时有效,因此很难找出问题所在。
任何帮助将不胜感激!
进一步调查显示 SMTP 服务器确实发送了 [220 localhost ESMTP],但在查看 hMailServer 日志后,我发现以下内容:
"TCPIP" 5232 "2010-06-16 11:40:54.043" "TCPConnection - Posting AcceptEx on 0.0.0.0:25"
"DEBUG" 5232 "2010-06-16 11:40:54.043" "Creating session 51"
"SMTPD" 5232 51 "2010-06-16 11:40:54.043" "127.0.0.1" "SENT: 220 localhost ESMTP"
"DEBUG" 5296 "2010-06-16 11:40:54.199" "The read operation failed. Bytes transferred: 0 Remote IP: 127.0.0.1, Session: 51, Code: 10054, Message: An existing connection was forcibly closed by the remote host"
"DEBUG" 5296 "2010-06-16 11:40:54.199" "Ending session 51"
会不会是 SwiftMailer 太早了 HELO/EHLO,这只是一个时间问题?我可以稍微延迟一下 HELO 传输吗?
当事物实际发送时,好的日志如下所示:
"TCPIP" 5232 "2010-06-16 11:42:21.278" "TCPConnection - Posting AcceptEx on 0.0.0.0:25"
"DEBUG" 5232 "2010-06-16 11:42:21.294" "Creating session 54"
"SMTPD" 5232 54 "2010-06-16 11:42:21.294" "127.0.0.1" "SENT: 220 localhost ESMTP"
"SMTPD" 5224 54 "2010-06-16 11:42:21.294" "127.0.0.1" "RECEIVED: EHLO splodge.loc"
所以它必须与 HELO/EHLO 确认有关。请指教!:)