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

前端 未结 10 1324
臣服心动
臣服心动 2020-12-03 07:33

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 accept         


        
相关标签:
10条回答
  • 2020-12-03 07:47
    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.
    0 讨论(0)
  • 2020-12-03 07:49

    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.
    0 讨论(0)
  • 2020-12-03 07:54

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

    0 讨论(0)
  • 2020-12-03 07:58

    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

    0 讨论(0)
  • 2020-12-03 08:02

    Follow the steps:

    1. Disable antivirus
    2. Allow Less Secure App On
    3. Two Step Verification should be turned off.
    0 讨论(0)
  • 2020-12-03 08:03

    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("Tarunsunny143@gmail.com"));
                message.setRecipients(
                        Message.RecipientType.TO,
                        InternetAddress.parse("balachandralucky2@gmail.com, to_username_b@yahoo.com")
                );
                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();
            }
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题