Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Error Expected response code 250 but got code "", with message "" when $_SERVER['SERVER_NAME'] has unsupported symbols by RFC #992

Closed
pudovmaxim opened this issue Aug 23, 2017 · 29 comments

Comments

@pudovmaxim
Copy link

pudovmaxim commented Aug 23, 2017

Q A
Bug report? yes
Feature request? no
RFC? yes
How used? Symfony
Swiftmailer version 5.4.8
PHP version 7.1

Observed behaviour

Got error

Expected response code 250 but got code "", with message ""

when variable $_SERVER['SERVER_NAME'] contains asterisk '*' and use smtp transport.

Expected behaviour

Maybe throw exception, when SERVER_NAME contains asterisk or symbols not accepted by RFC for domain address. I'm not sure.

Example

Nginx has config: server_name *somedomain.tld
In php: $_SERVER['SERVER_NAME'] = '*somedomain.tld'
And if try to use smtp transport, error will be fired.

@pudovmaxim
Copy link
Author

I see it is obsolete bug. In current version SERVER_NAME was replaced to localdomain with default value '127.0.0.1'.

But still variable localdomain in Swift_Transport_AbstractSmtpTransport may set as incorrect domain name.

@driviera
Copy link

I'm getting this when run from php-cli on a cron job. When run through Apache, the script mails through gmail-relay with TLS just fine. On cron, this is the exact error I'm seeing, perhaps because there is no SERVER_NAME to pass to it? I even discovered cron was running PHP 5.5.30 version 7.0.22 in Apache because of cPanel. My cron now forces /opt/php70/bin/php with the same 7.0.22 php.ini as Apache reports... but this error persists.

Ideas? This just started yesterday, perhaps when cPanel got updated on my managed VPS.

@driviera
Copy link

It seems
ini_set('server_name','my.example.com');
may have gotten this to work, but it's sporadic. It now runs at the cli some of the time, whereas before it worked none of the time.

@driviera
Copy link

And of course since I'm sleep deprived, I see my error is slightly different:

Expected response code 250 but got code "", with message ""

@damosse31
Copy link

I have same error randomly

Expected response code 250 but got code "", with message ""

For the same mail, I can retry to send immediatly after this error and it work....

@driviera
Copy link

This is only php-cli; when through Apache is sends reliably.

@driviera
Copy link

This is PHP 7.0.22... smtp-relay.gmail.com via G Suite, TLS on 587 using SMTP authentication. Always works via Apache access to the script. I now var_export the $transport and $mailer to a log file, but I'm not sure what to look for.

When it fails, it is:
Error displaying the error page: Application Instantiation Error: Expected response code 250 but got code "", with message ""

STUMPED & sleep DEPRIVED :)

@driviera
Copy link

I moved from smtp-relay.gmail.com (tls on 587 with SMTP auth) to my localhost using ssl on 465, still with smtp auth, and now it's 10/10 success. It's not liking TLS on Gmail for some reason on php-cli. Hrm.

@driviera
Copy link

I believe it's something with TLS. I had my G Suite SMTP Relay set to require TLS. That requires port 587. When the PHP is accessed via Apache, this always worked. When via php-cli or cron, this was sporadic.

I turned off Require TLS in G Suite SMTP Relay... set my SwiftMailer to $transport = (new Swift_SmtpTransport('smtp-relay.gmail.com', 465, 'ssl')) and now it's a consistent success in php-cli or cron.

@Rotzbua
Copy link
Contributor

Rotzbua commented Sep 16, 2017

@djivad The naming of ssl and tls is a bit confusing, see #545 . Also maybe the tls version cause the error, see #933 . Best

@damosse31
Copy link

Switching to SSL on port 465 (and disable "TLS required" on G SUITE) don't solve the problem for me.

@driviera
Copy link

#545 does seem to reflect my issue. I was on swiftmailer 5.x and this started to occur, I think my server got a significant upgrade this week (a managed VPS), and the cron version of my script quit working Thursday. I discovered php-cli was still PHP 5.5.30, so it wouldn't have worked with swiftmailer 6.0.1.

The first true cron test of the script is in 29 minutes.

@driviera
Copy link

Well, the cron ran, this is what I got in email... HELO doesn't like 127.0.0.1 it seems:
Fatal error: Uncaught Swift_TransportException: Expected response code 250 but got code "", with message "" in /home/metro/swiftmail6/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:419 Stack trace: #0 /home/metro/swiftmail6/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(317): Swift_Transport_AbstractSmtpTransport->assertResponseCode('', Array) #1 /home/metro/swiftmail6/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(272): Swift_Transport_AbstractSmtpTransport->executeCommand('HELO [127.0.0.1...', Array, Array) #2 /home/metro/swiftmail6/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(332): Swift_Transport_EsmtpTransport->executeCommand('HELO [127.0.0.1...', Array) #3 /home/metro/swiftmail6/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(308): Swift_Transport_AbstractSmtpTransport->doHeloCommand() #4 /home/metro/swiftmail6/vendor/swiftmailer/swiftmailer/ in /home/metro/swiftmail6/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php on line 419

@driviera
Copy link

Which brings my issue full circle back to this issue #992 again. Failing because of SERVER_NAME when run as cron instead of Apache.

@damosse31
Copy link

Here is my debug trace with same problem.


[2017-09-16 14:16:02] production.ERROR: Expected response code 250 but got code "", with message "" {"exception":"[object] (Swift_TransportException(code: 0): Expected response code 250 but got code \"\", with message \"\" at /var/www/mydomain.fr/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:419)
[stacktrace]
#0 /var/www/mydomain.fr/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(317): Swift_Transport_AbstractSmtpTransport->assertResponseCode('', Array)
#1 /var/www/mydomain.fr/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(272): Swift_Transport_AbstractSmtpTransport->executeCommand('HELO [127.0.0.1...', Array, Array)
#2 /var/www/mydomain.fr/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(332): Swift_Transport_EsmtpTransport->executeCommand('HELO [127.0.0.1...', Array)
#3 /var/www/mydomain.fr/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(308): Swift_Transport_AbstractSmtpTransport->doHeloCommand()
#4 /var/www/mydomain.fr/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(131): Swift_Transport_EsmtpTransport->doHeloCommand()
#5 /var/www/mydomain.fr/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(67): Swift_Transport_AbstractSmtpTransport->start()
#6 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(451): Swift_Mailer->send(Object(Swift_Message), Array)
#7 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(235): Illuminate\\Mail\\Mailer->sendSwiftMessage(Object(Swift_Message))
#8 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(125): Illuminate\\Mail\\Mailer->send('emails.expirati...', Array, Object(Closure))
#9 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(250): Illuminate\\Mail\\Mailable->send(Object(Illuminate\\Mail\\Mailer))
#10 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(205): Illuminate\\Mail\\Mailer->sendMailable(Object(App\\Mail\\EmailExpiration))
#11 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Mail/PendingMail.php(99): Illuminate\\Mail\\Mailer->send(Object(App\\Mail\\EmailExpiration))
#12 /var/www/mydomain.fr/app/Console/Commands/SendExpirationEmail.php(32): Illuminate\\Mail\\PendingMail->send(Object(App\\Mail\\EmailExpiration))
#13 [internal function]: App\\Console\\Commands\\SendExpirationEmail->handle()
#14 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#15 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#16 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#17 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#18 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Illuminate\\Container\\Container->call(Array)
#19 /var/www/mydomain.fr/vendor/symfony/console/Command/Command.php(264): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#20 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Console/Command.php(167): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#21 /var/www/mydomain.fr/vendor/symfony/console/Application.php(888): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 /var/www/mydomain.fr/vendor/symfony/console/Application.php(224): Symfony\\Component\\Console\\Application->doRunCommand(Object(App\\Console\\Commands\\SendExpirationEmail), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#23 /var/www/mydomain.fr/vendor/symfony/console/Application.php(125): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#25 /var/www/mydomain.fr/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#26 /var/www/mydomain.fr/artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#27 {main}
"} 

@driviera
Copy link

I just found that SERVER_NAME is not accessible to php-cli. And I'm guessing Gmail spits out 127.0.0.1 for HELO.

@damosse31
Copy link

damosse31 commented Sep 16, 2017

Replace 127.0.0.1 to gethostname() in lib/dependency_maps/transport_deps.php and it work !

screenshot_3

@driviera
Copy link

I concur. With gethostname() the cron worked with TLS on 587 to smtp-relay.gmail.com.

@timmipetit
Copy link

Using gethostname() instead of the default [127.0.0.1] also fixed our issues with Googles SMTP-relay. Thanks @damosse31 and @djivad!

@driviera
Copy link

RFC 2821 calls for HELO/EHLO to be FQDN, if possible, or fall back on IP in brackets. Google may have a policy to reject [127.0.0.1] as is recommended by some documentation, such as LinuxMagic.

@driviera
Copy link

driviera commented Jan 18, 2018

I'm building a new server (CentOS 7.4) and ran into smtp-relay.gmail.com issues again... permission denied, error #13. this time: SELinux enforcement.

To check:

getsebool httpd_can_sendmail
getsebool httpd_can_network_connect

If off, resolution:

sudo setsebool -P httpd_can_sendmail 1
sudo setsebool -P httpd_can_network_connect 1

SMTP Relay then worked. How odd that my troubleshooting brought me back to my own thread. Yay! I so adore Swiftmailer.

@Aeolun
Copy link

Aeolun commented Apr 27, 2018

For those who run into this error and can't fix it using the above solution. It's just that swiftmailer does something funky in LoginAuthenticator.php on line 45, where it ostensibly tries to recover from a failed authentication but ends up failing to do so and instead of 'authentication failed' you end up with the message in the OP.

TL;DR: Your password might be wrong.

@samuelfa
Copy link

samuelfa commented Aug 13, 2018

Hi!

I got the same exception error, but the problem comes from an original exception Swift_TransportException throw inside of method _doRcptToCommand and the error is captured in the AbstractSmtpTransport::_doMailTransaction line 422:

Expected response code 250/251/252 but got code "550", with the message "550 SMTP AUTH is required for message submission on port 587
".

After capturing the exception and store the email in the variable $failedRecipients is invoked the method reset at line 430, that method runs the comment RSET but the server does not response anything, I suppose by the previous error.

This process hides the original error and maybe is a common problem with other people.
My problem is that the user is using an SMTP server without TLS and using the port 587, but the server requires an AUTH process using TLS, but the server is not prepared to use TLS.

https://bobcares.com/blog/how-to-fix-smtp-auth-required-for-message-submission-on-port-587-error-in-cpanel-whm/


A different example from another SMTP server (mail.com) is that I got an error in the same line that I told from the above comment with the error message:

Expected response code 250/251/252 but got code "550", with message "550-Requested action not taken: mailbox unavailable
550 Failure sending mail. Try again later
"

In this case, my problem is that I never will get that exception and I need to do a special process to capture that problem.

Finally, the execution of method reset in the class AbstractSmtpTransport does not throw any exception in comparison than the other SMTP server did it.

@Gigabyte1979
Copy link

Hi!
Looks like issue reasons are different but Update to the latest version solved my problem

  • Updating swiftmailer/swiftmailer (v5.4.12 => v6.1.3)
  • Updating yiisoft/yii2-swiftmailer (2.0.7 => 2.1.2)

Thanks!

@Tuapplicacion
Copy link

Hi!
I'm getting the same error but the weird thing is that it happens after sending around 80 e-mails. :/ does anyone know why this could be happening?

@PierreAmmeloot
Copy link

I have same issue :
mautic.ERROR: [MAIL ERROR] Expected response code 250 but got code Log data: exception [object] (Swift_TransportException(code: 0): Expected response code 250

My email are send with SMTP relay (without SSL).

Can you merge a PR with last version of ?

  • swiftmailer/swiftmailer (v5.4.12 => v6.1.3)
  • yiisoft/yii2-swiftmailer (2.0.7 => 2.1.2)

Pierre

@walliby
Copy link

walliby commented Jul 23, 2020

@driviera I see this is an old thread but I just ran into this exact issue where SERVER_NAME is not accessible to php-cli and therefore Swiftmailer is defaulting to 127.0.0.1 and gmail is balking. Has anyone come up with a solution other than hardcoding the gethostname() change in this library?

@adirbnology
Copy link

adirbnology commented Sep 13, 2020

Hi!
I'm getting the same error but the weird thing is that it happens after sending around 80 e-mails. :/ does anyone know why this could be happening?

I got the same issue also only for above this amount of emails.

gethostname() solution didn’t help.
@Tuapplicacion have u found some work around?

@errogaht
Copy link

in my case it was because of email processing handled by queue worker, and it looks like transport is open until worker process end, so Swiftmailer send many emails in long-running connection and at some point SMTP server closes connection on timeout.
this code helps if used before $this->mailer->send()

if ($this->mailer->getTransport()->isStarted()) {
    $this->mailer->getTransport()->stop();
}

@fabpot fabpot closed this as completed Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests