How to fix Email Authentication issue in laravel? - laravel

I am sending email when user register but when I run my page it is showing me an error like this
Swift_TransportException: Failed to authenticate on SMTP server with
username "support#project.gmail.com" using 3 possible authenticators.
Authenticator LOGIN returned Expected response code 235 but got code
"535", with message "535-5.7.8 Username and Password not accepted.

if you are in development / local environment you can use service like mailtrap and put credentials in .env file

Related

laravel sengrid random authentication failure when sending emails with attachment

We are able to send out emails but a problem seems to occur when the email has an attachment.
we're getting this authentication error which is weird because we are able to send out no attachment emails so I'm not sure why it suddenly fails to authenticate.
Symfony\Component\Mailer\Exception\TransportException: Failed to
authenticate on SMTP server with username "myemail#email.com" using
the following authenticators: "LOGIN", "XOAUTH2". Authenticator
"LOGIN" returned "Expected response code "235" but got code "535",
with message "535 5.7.139 Authentication unsuccessful, the user
credentials were incorrect. [xxx.xxx.PROD.OUTLOOK.COM]".".
Authenticator "XOAUTH2" returned "Expected response code "235" but got
code "535", with message "535 5.7.3 Authentication unsuccessful
[xxx.xxx.PROD.OUTLOOK.COM]".". in
/var/www/project/vendor/symfony/mailer/Transport/Smtp/EsmtpTransport.php:198
Is this something related to our SendGrid configuration that we've missed? or could this be a server-related problem since our test server is able to send out emails with attachments fine? just this one live server is having the issue
Our test server is also using the same SendGrid account with a different API key and is able to send out emails with attachments okay.
We are using ubuntu and nginx

Gmail smtp not working with only one email

I am using gmail smtp in my laravel, It was working fine till yesterday but it suddenly stopped, I am getting this error
Failed to authenticate on SMTP server with username "email#gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted
Less secure apps was already on so i added 2 factor auth and created an app password but still not working, I created a test email and it worked fine, why is not working with my first email
This is my setting in env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=email#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_EMAIL_ADDRESS=email#gmail.com
I also tried by adding double quotes, but still not wokring,
Can anyone please help
After the removal of less secure apps. You can no longer connect to googles smtp server using the actual password of the users gmail account.
YOu have two options.
enable 2fa on the google account and create an apps password. The apps password can then be used in place of the password in your code.
Switch to using Xoauth2.

"Failed to authenticate on SMTP server" after more than 100 emails

I'm trying to send about 500 emails with Laravel, my provider is Gmail.
The first 150 emails (more or less) are sent correctly, but after I receive this error:
"Failed to authenticate on SMTP server with username "XXXXXXX" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 250 but got an empty response. Authenticator PLAIN returned Expected response code 250 but got an empty response. Authenticator XOAUTH2 returned Expected response code 250 but got an empty response."
My .env is
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=ssl
MAIL_USERNAME=...
MAIL_PASSWORD=...
I also tried to wait for about 5 seconds between each email, but it doesn't work.
Anyone knows how I can handle this?
Thank you
Try to use the next settings:
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
Enable 2FA in your Google account and create an app password.
Use it in MAIL_PASSWORD
I had a similar problem, and here is how I solved it.
the Google mail service may have blocked emails from being sent from your app. Google surely viewed this as a security threat. you should definitely receive a security alert in your mailbox.
You just have to admit that it was you who tried to access the account or just change your gmail password. after that please change the info in the .env file and i think it will work.
try to change your password on gmail
and also in your .env file

Sending Email using Outlook / Office365 with Laravel - Failed to authenticate on SMTP server

I'm trying to send an email with our Laravel app using Office365/Outlook. It has worked well with gmail but when I switched over to Office365, the following error appears:
Failed to authenticate on SMTP server with username
"xxxxxx#companyname.co" using 2 possible authenticators. Authenticator
LOGIN returned Expected response code 235 but got code "535", with
message "535 5.7.3 Authentication unsuccessful
[HKAPR03CA0035.apcprd03.prod.outlook.com]
". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful
[HKAPR03CA0035.apcprd03.prod.outlook.com]
".
This is what I have in my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx#companyname.co
MAIL_PASSWORD=emailPassword
MAIL_ENCRYPTION=tls
MAIL_SMTPAuth=true
MAIL_FROM_NAME=CompanyName
MAIL_FROM_ADDRESS=xxxxxx#companyname.co
*note: this is not the real username, password and from address.
I also tried changing the port to 25 but I get the same error
I'm using a dedicated support email from my company. And from what I confirmed with our IT, the support email does not have 2 factor authentication and the "Authenticated SMTP" setting is also enabled via the admin panel of Office365 so I don't know what seems to be the problem.
Keep in mind that for the new tenants, Microsoft turns SMTP authentication off, and it needs to be explicitly enabled. Please see
Enable or disable authenticated client SMTP submission (SMTP AUTH) in Exchange Online
as well as
What are security defaults?
I had the same issue and I called Microsoft support. They instructed me to change some security properties in Microsoft Azure. Here is my answer.
You have to enable the 2 factor authentication, the go to your account settings and create an application password. Then you have to use the new application password in your code. Check this link

Laravel SMTP Gmail failed

Failed to authenticate on SMTP server with username "user#email.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials 70sm7122401qkk.10 - gsmtp
". Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials 70sm7122401qkk.10 - gsmtp
". Authenticator XOAUTH2 returned Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials 70sm7122401qkk.10 - gsmtp
".
Good morning, I'm trying to connect Gmail Smtp, above is the error that I get in laravel 5.8, I generated the application password on my personal mail, then sending emails worked, but as when I generated the application password on work mail, I immediately get the error. That is, when I use my personal mail with the application password, then everything is OK, but as soon as I use work mail I immediately get an error.
On both mailboxes I did the following actions, which are described in Google support
https://support.google.com/accounts/answer/185833
https://support.google.com/mail/?p=BadCredentials
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=user#email.com
MAIL_PASSWORD=generatedAppPassword
MAIL_ENCRYPTION=tls
So if you can help me do this, I would really appreciate
Make sure you account has “Access for less secure apps” enabled and that 2fa login is not enabled.
Update 2022
after the removal of less secure apps. You can no longer connect to googles smtp server using the actual password of the users gmail account.
You have two options.
enable 2fa on the google account and create an apps password. The apps password can then be used in place of the password in your code.
Switch to using Xoauth2.
Quick fix for SMTP username and password not accepted error
i had same issue i resolve this use under
go to gmail.com
my account
and enable
Allow less secure apps: ON
it start works

Resources