Failed to authenticate with SMTP server error using gmail

I am trying to set up email for my first laravel project and was thrilled to have laracast there: https://laracasts.com/lessons/mailers

I followed the simple steps, chose gmail in mail.php (x added for anonymity):

'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST', 'smtp.gmail.com'), 'port' => env('MAIL_PORT', 587), 'from' => ['address' => ' dianexxxxx@gmail.com ', 'name' => 'Diane Kaplan'], 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => ' dianexxxxx@gmail.com ', 'password' => 'xxxxx', 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false, 

.env has (x added for anonymity) - laracast does not use us MAIL_USERNAME and MAIL_PASSWORD, but they are updated for a good rating, assuming that I come from there later:

 MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=dianexxxxx@gmail.com MAIL_PASSWORD=xxxxxx MAIL_ENCRYPTION=null 

But in the first moment of truth, trying to send mail (mark 3:30), I get an authentication error: Swift_TransportException in the AuthHandler.php line 181: Authentication on the SMTP server with the username " dianexxxxx@gmail.com " failed, using 3 possible authenticator

Based on a small read on the stack, I tried to enable "access to less secure applications" in gmail settings, but no changes in the error. (And other reports about this issue were related to other factors that caused a more serious problem than mine).

Nothing jumps at me from laravel.log (below) - any ideas?

 [2015-11-26 12:25:55] local.ERROR: exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username " dianekaplan@gmail.com " using 3 possible authenticators' in /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:181 Stack trace: #0 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) #1 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(118): Swift_Transport_EsmtpTransport->_doHeloCommand() #2 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(395): Swift_Mailer->send(Object(Swift_Message), Array) #4 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(181): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message)) #5 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(220): Illuminate\Mail\Mailer->send('emails.welcome', Array, Object(Closure)) #6 /home/vagrant/Code/Family-laravel/app/Http/routes.php(59): Illuminate\Support\Facades\Facade::__callStatic('send', Array) #7 /home/vagrant/Code/Family-laravel/app/Http/routes.php(59): Illuminate\Support\Facades\Mail::send('emails.welcome', Array, Object(Closure)) #8 [internal function]: App\Providers\RouteServiceProvider->{closure}() #9 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(155): call_user_func_array(Object(Closure), Array) #10 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(130): Illuminate\Routing\Route->runCallable(Object(Illuminate\Http\Request)) #11 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(704): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) #12 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #13 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #15 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #16 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(706): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #17 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(671): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request)) #18 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(631): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) #19 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(236): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) #20 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request)) #21 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #22 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #23 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure)) #24 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #25 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #26 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure)) #27 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #28 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #29 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure)) #30 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #31 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #32 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure)) #33 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #34 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #35 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure)) #36 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #37 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #38 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) #39 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array) #40 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #41 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #42 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #43 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) #44 /home/vagrant/Code/Family-laravel/public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #45 {main} 
+14
source share
7 answers

Have you enabled "Allow less secure apps"? follow this link

https://myaccount.google.com/security#connectedapps

Take a look at the Login and Security menu β†’ Applications with account access.

You must enable the "Allow less secure applications" option.

If still not working, try one of them:

And change your .env file

 MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=dianexxxxx@gmail.com MAIL_PASSWORD=xxxxxx MAIL_ENCRYPTION=tls 

because the one you specified in mail.php will only be used if the value is not available in the .env file.

+42
source

Your method is okay, this is an email security issue.

  1. Email account login settings.

  2. Enable two-step verification.

  3. Create application password .

  4. Use the new generated password instead of your real email password.

Remember to clear the cache.

 php artisan config:cache. php artisan config:clear. MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=587 MAIL_USERNAME=yourgmailid@gmail.com MAIL_PASSWORD=generatedAppPassword MAIL_ENCRYPTION=tls 
+11
source

I had the same problem, but when I ran the following command, it was fine:

 php artisan config:cache 
+4
source

Here is how I solved this problem:

  • Modify the .env file as follows

Screen shot reference

  1. Never forget to restart the server after modifying the .env file
+1
source

I had the same problem and I already tried everything and nothing worked until I just changed the value of 'host' in config.php to:

  'host' => env('smtp.mailtrap.io'), 

When I changed this, it worked well, somehow it used the default host "smtp.mailtrap.org" and ignored the .env variable that I set.

After some testing, I understand that if I put the env variable in that order, it would work the way it should:

MAIL_HOST = smtp.mailtrap.io

MAIL_DRIVER = SMTP

MAIL_PORT = 2525

MAIL_USERNAME = xxxx

MAIL_PASSWORD = xxx

MAIL_ENCRYPTION = zero

+1
source

I had this error:

"Authentication failed on the SMTP server with the username" email@company.com. "Using 3 possible authenticators. LOGIN authorization returned Swift_TransportException: expected response code 235, but received code" 535 "with the message" 535-5.7.8 Username and password not found "accepted. More on 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 75sm6289114otc.67 - gsmtp"

Maharjan's Milan answer solved my problem! Thanks dude.

0
source

If you still get this error when sending e-mail: "Failed to authenticate to the SMTP server with the username" youremail@gmail.com "using 3 possible authenticators"

You can try one of the following methods:

Go to https://accounts.google.com/UnlockCaptcha , click "Continue" and unlock your account to access through other media / sites.

Using the password in double quotes: "your password". & lt; - This also solved my problem.

0
source

Source: https://habr.com/ru/post/1236906/


All Articles