Reputation: 38
I have an issue with authentication while sending mail with Laravel smtp driver.
.env
file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
[email protected]
MAIL_PASSWORD=app_password
MAIL_ENCRYPTION=tls
It gives the following error:
"530-5.7.0 Authentication Required. "
2-Factor auth is enabled and app password is used;
Also tried with SSL on 465, same error;
Config is flushed every time .env is changed;
Everything in config/mail corresponds to .env;
SO all typical solutions are not working. What else may cause this problem?
I have also tried using smtp.vivaldi.net with vivaldi account, it authenticates, but gives an error:
"no valid recipients"
while recipient email is surely valid, which is also strange for me.
Upvotes: 0
Views: 570
Reputation: 38
Problem was that I messed up with config/mail.php
.
I wrote
'username' => env('email'),
'password' => env('app_password'),
Instead of
'username' => env('MAIL_USERNAME','email'),
'password' => env('MAIL_PASSWORD','app_password'),
Upvotes: 0
Reputation: 2007
I've stumbled across this multiple times already, hence I do not remember the exact error-message which I received but here is my assumption.
Google has an option called "less secure apps" which you need to enable in order to send directly mails through their SMTP interface. Can you check if this flag is disabled and try to enable it?
https://support.google.com/a/answer/6260879
In addition to that google is slowly deprecating this feature. Starting from Mid 2020 you'll be not able to enable this flag anymore and they will completely remove this in 2021.
Upvotes: 2
Reputation: 34678
Firstly, you need to setup 2 step verification here google security. An App Password link will appear and you can get your App Password to insert into below "MAIL_PASSWORD". More info on getting App Password here
MAIL_DRIVER=smtp
[email protected]
MAIL_FROM_NAME=System
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=YOUR_GMAIL_CREATED_APP_PASSWORD
MAIL_ENCRYPTION=tls
Don't forget to clear cache with :
php artisan config:cache
Upvotes: 0