doudian6229 2014-03-21 14:50
浏览 51
已采纳

在Symfony 2中轻松配置SwiftMailer“Local Domain”设置

SwiftMailer is the default way of sending email from a Symfony 2 project, and I'd like to use it in an application. I've pointed it towards the SMTP server provided by my internet provider (Virgin Media, in the UK), but my emails are not successfully sent. The exception thrown says

Expected response code 250 but got code "501", with message "501 HELO requires valid address

in response to the SMTP command

HELO [::1]

[::1] corresponds to localhost in IPv6, and it's not that surprising that the SMTP server would reject that if it's expecting a proper domain name. Tracing execution through the Swiftmailer source, I find that this value comes from _domain on AbstractSmtpTransport; altering the value during the debug session allows the email to be sent. Although it can be set using the public setLocalDomain() method, it isn't anywhere in the Symfony 2 framework, so it seems that there is no way (obvious to me, at least) of easily configuring this value simply by, for example, changing a Symfony config file.

So my question is this: is there some other way of changing this value, ideally using config, without my diving into the Symfony code and changing bits that aren't meant to be changed? And if so, what?

  • 写回答

2条回答 默认 最新

  • dongpao1921 2014-04-07 10:47
    关注

    Unfortunately no.

    The code for get the local domain in SwiftMailer is:

    /** Try to determine the hostname of the server this is run on */
    private function _lookupHostname()
    {
        if (!empty($_SERVER['SERVER_NAME'])
            && $this->_isFqdn($_SERVER['SERVER_NAME']))
        {
            $this->_domain = $_SERVER['SERVER_NAME'];
        } elseif (!empty($_SERVER['SERVER_ADDR'])) {
            $this->_domain = sprintf('[%s]', $_SERVER['SERVER_ADDR']);
        }
    }
    

    So, is guessed and it's server configuration.

    I opened an issue for SwiftMailer to do this:

    https://github.com/swiftmailer/swiftmailer/issues/453

    UPDATE: The issue has been resolved on Feb 27th 2018.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?