title: When I send mail Then Found Error javax.mail.AuthenticationFailedException: 535 Incorrect authentication data
body: <p>I got the below error when sending an email through the below code </p>
  
  <p><code>javax.mail.AuthenticationFailedException: 535 Incorrect authentication data</code> </p>
  
  <p>What could be the problem in my code .</p>
  
  <pre><code>public class SendMail {
  
      public static boolean sendHTMLMail(final String from, final String password, String senderName, String sub, String msg, String[] to) {
  
          String host = "mail.xxxx.org";
          MimeMultipart multipart = new MimeMultipart();
          MimeBodyPart bodypart = new MimeBodyPart();
          Properties p = new Properties();
          p.setProperty("mail.smtp.host", host);
          p.put("mail.smtp.port", 587);
          p.put("mail.smtp.auth", "true");
  
          try {
              Session session = Session.getInstance(p, new javax.mail.Authenticator() {
                  @Override
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication(from, password);
                  }
              });
              Transport transport = session.getTransport("smtp");
              MimeMessage mimeMessage = new MimeMessage(session);
              mimeMessage.setFrom(new InternetAddress("" + senderName + "&lt;" + from + "&gt;"));
              InternetAddress[] toAddress = new InternetAddress[to.length];
              for (int i = 0; i &lt; to.length; i++) {
                  toAddress[i] = new InternetAddress(to[i]);
              }
  
              for (InternetAddress toAddres : toAddress) {
                  mimeMessage.addRecipient(Message.RecipientType.TO, toAddres);
              }
              bodypart.setContent(msg, "text/html; charset=\"utf-8\"");
              multipart.addBodyPart(bodypart);
              mimeMessage.setSubject(sub);
              mimeMessage.setContent(multipart);
              transport.connect(host, from, password);
              mimeMessage.saveChanges();
              Transport.send(mimeMessage);
              transport.close();
              return true;
          } catch (MessagingException me) {
              me.printStackTrace();
          }
          return false;
      }
  }
  </code></pre>