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

JavaJakarta Mail

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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"

Solution 3 - Java

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

Solution 4 - Java

  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.

Solution 5 - Java

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"

Solution 6 - Java

Log on gmail account, in Account ->

click Security -> turn off 2-step verification and turn on "Less secure app access"

May be because of things above, hope help you

Solution 7 - Java

I have the same error but when I run the app from the terminal, it goes away. My email configuration is provided:

spring.mail.host=smtp.googlemail.com
spring.mail.username[email protected]
spring.mail.password=Weddingcard.1
spring.mail.port=587
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.required=true

Solution 8 - Java

Follow the steps:

  1. Disable antivirus
  2. Allow Less Secure App On
  3. Two Step Verification should be turned off.

Solution 9 - Java

1.Allow Less Secure App(should be turned on).

2.Check Gmail Username and Password..

 public static void main(String[] args) {

        final String username = "YourMailId";
        final String password = "password";

        Properties prop = new Properties();
		prop.put("mail.smtp.host", "smtp.gmail.com");
        prop.put("mail.smtp.port", "587");
        prop.put("mail.smtp.auth", "true");
        prop.put("mail.smtp.starttls.enable", "true"); //TLS
        
        Session session = Session.getInstance(prop,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("[email protected]"));
            message.setRecipients(
                    Message.RecipientType.TO,
                    InternetAddress.parse("[email protected], [email protected]")
            );
            message.setSubject("Testing Gmail TLS");
            message.setText("Dear Mail Crawler,"
                    + "\n\n Please do not spam my email!");

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

}

Solution 10 - Java

Please turn on by clicking the toggle button inside the google security panel. Then it will allow less secured app also.

enter image description here

Solution 11 - Java

Change the settings in Google like this:

https://i.stack.imgur.com/DidAj.png

Solution 12 - Java

You probably got this error because the username and password of the from mail id is not matching. Please recheck your password and mail-id (username). It could be a typo.

In some cases, Gmail prevents logging in through external applications or programs which are not authorised. Also login to your gmail account to check if gmail has prevented logging in to your account via your Java Mail API program.

If nothing works, you could try some other SMTP server (like yahoo, yandex).

Solution 13 - Java

For me works change the property "mail.host" recomended for @Heisenberg.

At documentation says to use "smtp.gmail.com" but works only I use "smtp.googlemail.com".

PS: My Allow Less Secure App configuration was already On

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRohit RajView Question on Stackoverflow
Solution 1 - JavaThinkTankView Answer on Stackoverflow
Solution 2 - JavaognjenklView Answer on Stackoverflow
Solution 3 - JavaVladiView Answer on Stackoverflow
Solution 4 - Javauser3769960View Answer on Stackoverflow
Solution 5 - JavaY.LAGHOUAZIView Answer on Stackoverflow
Solution 6 - JavaNguyễn DươngView Answer on Stackoverflow
Solution 7 - JavaArefeView Answer on Stackoverflow
Solution 8 - JavaKP DeveloperView Answer on Stackoverflow
Solution 9 - Javatarun kumar143View Answer on Stackoverflow
Solution 10 - JavaspainView Answer on Stackoverflow
Solution 11 - JavaLasan RashmikaView Answer on Stackoverflow
Solution 12 - JavaMathews MathaiView Answer on Stackoverflow
Solution 13 - JavaguinogueirasView Answer on Stackoverflow