Swiftmailer SMTP 传输拒绝本地 IP 地址 [英] Swiftmailer SMTP transport rejecting local IP address

查看:65
本文介绍了Swiftmailer SMTP 传输拒绝本地 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Swift_SmtpTransport 发送电子邮件,但出现以下错误:

I'm trying to send an email using the Swift_SmtpTransport but I'm getting the following error:

501 5.5.2 <[::1]>: Helo 命令被拒绝:IP 地址无效

501 5.5.2 <[::1]>: Helo command rejected: invalid ip address

SMTP 服务器是一个远程服务器,它可以在我的生产服务器上运行,但不能在我运行 OS X 的开发机器上运行.

The SMTP server is a remote server and it works from my production server, but not from my development machine, which is running OS X.

它也不会抛出异常,而是需要我使用记录器插件来找出它不工作的原因.

It also doesn't bother to throw an exception, instead it required me to use a logger plugin to find out why it wasn't working.

我该怎么做才能让它使用真实的 IP 地址?

What can I do to make it use a real IP address?

推荐答案

我在代码中进行了一些探索并找到了它.

I did some poking around in the code and found it.

配置 SMTP 传输时,需要调用 setLocalDomain().在 OS X 上使用 PHP,它默认为::1",它被远程服务器拒绝.我刚刚在我的开发配置中添加了一行来设置:

When configuring the SMTP transport, you need to call setLocalDomain(). Using PHP on OS X, this defaults to "::1", which is rejected by the remote server. I've just added a line in my development configuration to set that:

$transport = Swift_SmtpTransport::newInstance('mail.pantsburger.com', 587);
if (SITE_ENV == SITE_ENV_DEV) {
    $transport->setLocalDomain('[127.0.0.1]');
}

我认为这也是 Swiftmailer 的一个错误——它真的应该为这样的事情抛出异常,而不是仅仅将每个收件人列为失败".

I think this is also a bug with Swiftmailer - it really should be throwing an exception for something like this, rather than just listing each recipient as "failed".

这篇关于Swiftmailer SMTP 传输拒绝本地 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆