2
votes

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
the issue has been resolved almost 4 years later... waiting for a release..Alfonso Tienda
[gasp] Amazing! :)frumious

2 Answers

2
votes

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.

3
votes

From inside a Symfony controller, you can configure the HELO/EHLO name like that: $this->get('swiftmailer.transport')->setLocalDomain('your.domain');