[Fix] javax.mail.AuthenticationFailedException 535-5.7.8 Username and Password not accepted

The error “javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. ” is an error that is invoked whenever you are coding in java and trying to send mails through your java app. Given below is the snippet of the error:

javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. 

I would like to share with you the steps I took to fix the “javax.mail.AuthenticationFailedException 535-5.7.8 Username and Password not accepted. ” in your project file.

Why Javax.mail.AuthenticationFailedException 535-5.7.8 Username and Password not accepted error is seen?

The error, “javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. ” is seen because you have not setup the “app password” into your google account for authentication purpose.

To be able to send mails or messages through your Gmail account by integrating Java app, you have to set up an “app password” as a two-factor authentication for additional security in your Google account.

Google has recently announced that it will not be continuing its “Less Secure Apps” features on some Google accounts from May 30th, 2022.

The detailed solution to fix the error “javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted.”, is given below:

How to fix javax.mail.AuthenticationFailedException 535-5.7.8 Username and Password not accepted Error?

To fix the error, You will have to set up an app password in your Google account and it would fix the error immediately.

To be able to send mails or messages through your Gmail account by integrating Java app, you have to set up an “app password” as a two-factor authentication for additional security in your Google account.

To fix the error, “Javax.mail.AuthenticationFailedException 535-5.7.8 Username and Password not accepted”, you will have to set up an app password in your Google account, by following the below mentioned steps:

An application password works like as second password for your main account password. It will only be used for the applications you share it with, which is the reason why it is more safe than sharing your main password

In case you would like to use an application password, you would need to switch on your two factor authentication for your Google account . After you have done the above steps, you will be able to create an app specific password for WP Mail SMTP in the security settings with your Google account.

If you wish to do so, choose any other name as the app on the App passwords screen.

enter image description here

The next step would be to type in WP Mail SMTP or any other name which would help you identify this password in the space provided.

enter image description here

After that, you just need to click the Generate button to create your password.

enter image description here

Please make a note that at any time you change your primary Google account password, it would deactivate your app passwords as well. If you change your password frequently, this may not be the best workaround.

Once your “app password” is generated into google account, you need to put your generated password in password property of your property file in java code like the below mentioned code:

 mail:
    host: smtp.gmail.com
    username: mail@gmail.com
    password: <GENERATED_PASSWORD>
    port: 465
    protocol: smtps

This should fix the error, “javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. ” task was not found”.

Conclusion

To fix the error “javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. ” task was not found”, you have to set up an “app password” as a two-factor authentication for additional security in your Google account.