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
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
Laravel 9 - Infomaniak: Expected response code '250' but received code '550' with message '550 5.7.1 Sender Mismatch'
https://stackoverflow.com/a/43283422/11752623
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.
Found the solution, I accessed
vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php
under assertResponseCode method. I responded with a reply that showed: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
fileMore information: