Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 691
Rohit Raj Avatar asked Feb 11 '16 18:02

Rohit Raj


4 Answers

Sorry for coming late to Party.These could be the problem in your task if you are using Gmail Server.

  1. Two Step Verification should be turned off.
  2. Allow Less Secure App(should be turned on).
  3. Please Check Your UserName and Password.
  4. 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.
like image 121
ThinkTank Avatar answered Nov 16 '22 22:11

ThinkTank


This worked for me:

  1. Login to the gmail account you are sending mail from
  2. 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
  3. Turn "Allow less secure apps: OFF" to "Allow less secure apps: ON"

Update: Google stopped supporting "Less Secure Apps" as of May 30th, 2022.

One of the alternatives to solve this problem is to use 2-Step Verification and generate app password:

  1. Google Account -> Security -> 2-Step Verification -> Input password as asked -> Turn ON (you could use SMS to get Gmail code to activate 2-Step Verification)
  2. Google Account -> Security -> App password -> Input password as asked -> Select the app and device... -> e.g. Other(Custom name) -> Input app name e.g. MyApp -> Generate
  3. Copy a 16-character password
  4. Use a 16-character password with Gmail username in your application

Google support link here.

like image 47
ognjenkl Avatar answered Nov 16 '22 22:11

ognjenkl


Update since June 2022: Google closed the "Less secure app access", but opened another option called "App Passwords":

"When you use 2-Step Verification, some less secure apps or devices may be blocked from accessing your Google Account. App Passwords are a way to let the blocked app or device access your Google Account." (see docs).

Follow this answer to set up App Passwords

Hint: when using Jenkins Email Extension Plugin, emailext (which does not permit tokens like Google's App Passwords, still requiring logins), just use App Password as the password, and supply any string as login, e.g. your Gmail address login.


OLD ANSWER , not relevant anymore

Step 1: Log into your gmail account

Step 2: Click Settings

enter image description here

Step 3: Click the Accounts and Import Tab > Other Google Account Settings

enter image description here

Step 4: Click Security

  • Scroll to the bottom of the page Under Less secure app access, click on Turn on access

enter image description here

Step 5: Set Allow less secure apps to ON

enter image description here

like image 32
Vladi Avatar answered Nov 16 '22 20:11

Vladi


  1. 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

  1. Now,make sure that two step verification is off

  2. Allow less secure app (ON) follow this link :-

https://myaccount.google.com/lesssecureapps

  1. Also, check your username and password is correct or not.
like image 8
user3769960 Avatar answered Nov 16 '22 20:11

user3769960