Header rewritten to: Symfony\Component\Mailer\Exception\TransportException: Expected response code '250' but received an empty response
P粉350036783
P粉350036783 2023-11-03 21:58:49
0
1
759

I'm using the Google Workspace SMTP relay service to send emails from my Laravel app. It's been working fine for over a year now, but I'm not sure what exactly is stopping it from running. When I try to send an email I get the following error:

>>> IlluminateSupportFacadesMail::to('myemail@gmail.com')->send(new AppMailCourseEnrolmentEmail($user, AppCourse::first()));

// The error
SymfonyComponentMailerExceptionTransportException with message 'Expected response code "250" but got an empty response.'

I suspect this is related to me upgrading from Laravel 8 to Laravel 9, but not sure how to fix it.

Mymail.php

'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
        ],

My email configuration

MAIL_DRIVER=smtp
MAIL_HOST=smtp-relay.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=TLS
MAIL_FROM_NAME="My Name"
MAIL_FROM_ADDRESS=myaddress@workspace.com

I authenticate via IP so the password and username fields are not required

My GSuite Gmail routing configuration


Note In the configuration above, I tried checking TLS and changing the allowed senders to "Only registered application users in my domain" but the problem persists.

I tried the suggestion from

  1. https://laracasts.com/discuss/channels/laravel/laravel-swift-mailer-exception-expected-response-code-250-but-got-an-empty-response-using-gmail- smtp relay database queue driver

  2. Laravel 9 - Infomaniak: Expected response code '250' but received code '550' with message '550 5.7.1 Sender Mismatch'

  3. https://stackoverflow.com/a/43283422/11752623

  4. https://www.cubebackup.com/blog/how-to-use-google-smtp-service-to-send-emails-for-free/ Method 3

All of these were unsuccessful. Thanks for your help in resolving this issue.

P粉350036783
P粉350036783

reply all(1)
P粉221046425

Found the solution, I accessed vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php under assertResponseCode method. I responded with a reply that showed:

421 4.7.0 Try again later, closing connection. (EHLO) r29-200a50c01d0000xxxxxxxxxxxx87edb.28 - gsmtp

For more details about this error, please see Google Docs

The problem is that Swift Mailer uses 127.0.0.1 as the domain to send unknown emails to Gmail.

So the solution was to set my domain name in the config/mail.php file

        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN', 'mydomain.com')//this line here
        ],

More information:

  1. https://insights.rytass.com/gmail-smtp-relay-421-4-7-0-try-again-later- opening-connection-ehlo-cfcdac3cf9c7
  2. https://serverfault .com/questions/929559/postfix-error-421-4-7-0-try-again-later-opening-connection-ehlo
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template