Home > Software design >  javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more a
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more a

Time:07-11

I'm trying to send mails using my java app and gmail. Here is my config:

  mail:
    host: smtp.gmail.com
    username: [email protected]
    password: password
    port: 465
    protocol: smtps

But, unfortunately I'm getting following error:

javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials l18-20020a056402345200b0043a5004e714sm3019845edc.64 - gsmtp

        at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:947)
        at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:858)

I have enabled access to less secured apps on my gmail account and I'm sure that provided username and password are valid.

Can someone help me with this?

Thanks

CodePudding user response:

Google has announced that it’s disabling the Less Secure Apps feature on some Google accounts from May 30th, 2022.

To be able to send messages through your gmail account, you can set up an app password in your Google account.

An app password works like an alternate password for your account. It can only be used by the applications you share it with, so it’s more secure than sharing your primary password

If you’d like to use an app password,enter image description here

Then type in WP Mail SMTP or another name that will 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

Note: any time you change your main Google account password, it will deactivate your app passwords as well. If you change your password frequently, this may not be the best workaround.

After generating password, you put your generated password in password property of your property file:

 mail:
    host: smtp.gmail.com
    username: [email protected]
    password: <GENERATED_PASSWORD>
    port: 465
    protocol: smtps
  • Related