javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted
I am getting this error when I try to send mail using the JavaMail API:
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted
How can I fix this?
Solution 1:
Sorry for coming late to Party.These could be the problem in your task if you are using Gmail Server.
- Two Step Verification should be turned off.
- Allow Less Secure App(should be turned on).
- Please Check Your UserName and Password.
- Check the code(which was my Problem), Above three You can change form google help center and by Yourself last one My Experience I can Share with You. You need to Authenticate the Mail server before Communicating the message because it is Challenge Response System By which You are Communicating through the mail.I am sharing code snippets file you can refer not able to format my code by ctrl+K.
Solution 2:
This worked for me:
- Login to the gmail account you are sending mail from
- Go to Manage your Google Account -> Security -> Less secure app access -> Turn on access (not recommended)
or
Access the URL:
https://www.google.com/settings/security/lesssecureapps - Turn "Allow less secure apps: OFF" to "Allow less secure apps: ON"
Solution 3:
Step 1: Log into your gmail account
Step 2: Click Settings
Step 3: Click the Accounts and Import Tab > Other Google Account Settings
Step 4: Click Security
- Scroll to the bottom of the page Under Less secure app access, click on Turn on access
Step 5: Set Allow less secure apps to ON
Solution 4:
- First of all make sure that all properties should be defined as follows:-
mail.smtp.host=smtp.gmail.com
,
mail.smtp.port=25
,
mail.smtp.auth=true
mail.smtp.starttls.enable=true
Now,make sure that two step verification is off
Allow less secure app (ON) follow this link :-
https://myaccount.google.com/lesssecureapps
- Also, check your username and password is correct or not.
Solution 5:
It works for me, you must configure your Gmail account with the below steps:
In the security section:
You need to Change "Allow less secure apps: OFF" to "Allow less secure apps: ON"