Home  >  Q&A  >  body text

Header rewritten to: Symfony\Component\Mailer\Exception\TransportException: Expected response code '250' but received an empty response

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粉350036783P粉350036783324 days ago644

reply all(1)I'll reply

  • P粉221046425

    P粉2210464252023-11-04 15:51:18

    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

    reply
    0
  • Cancelreply