JavaMail 535 Authentication Error

JavaMail 535 Authentication Error

I'm trying to send an email via a program using the following bit of code:

  1. final String username = "xxxxx@xxxxx.com";
  2. final String password = "abc";
  3.         String to = "yyy@yyy.com";
  4.         String from = "xxxxx@xxxxx.com";
  5.         // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!
  6.         String host = "smtp.zoho.com";
  7.  
  8.         // Create properties, get Session
  9.         Properties props = new Properties();
  10.  
  11.         props.put("mail.smtp.auth", "true");
  12.         props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
  13.         props.setProperty("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
  14.         props.setProperty("mail.smtp.socketFactory.fallback","false");
  15.         props.setProperty("mail.smtp.socketFactory.port","465"); //443 or 465
  16.         props.put("mail.smtp.startssl.enable", "true");
  17.         // If using static Transport.send(),
  18.         // need to specify which host to send it to
  19.         props.put("mail.smtp.host", host);
  20.         // To see what is going on behind the scene
  21.         props.put("mail.debug", "true");
  22.         Session session = Session.getInstance(props,
  23.           new javax.mail.Authenticator() {
  24.         protected PasswordAuthentication getPasswordAuthentication() {
  25.         return new PasswordAuthentication(username, password);
  26.         }
  27.           });
  28.  
  29.         try {
  30.             // Instantiate a message
  31.             Message msg = new MimeMessage(session);
  32.  
  33.             //Set message attributes
  34.             msg.setFrom(new InternetAddress(from));
  35.             InternetAddress[] address = {new InternetAddress(to)};
  36.             msg.setRecipients(Message.RecipientType.TO, address);
  37.             msg.setSubject("Test E-Mail through Java");
  38.             msg.setSentDate(new Date());
  39.  
  40.             // Set message content
  41.             msg.setText("This is a test of sending a " +
  42.                         "plain text e-mail through Java.\n" +
  43.                         "Here is line 2.");
  44.  
  45.             //Send the message
  46.             Transport.send(msg);
  47.         }
  48.         catch (MessagingException mex) {
  49.             // Prints all nested (chained) exceptions as well
  50.             mex.printStackTrace();
  51.         }
However, it fails with the following exception: 

javax.mail.AuthenticationFailedException: 535 Authentication Failed

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:892)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:814)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:728)
at javax.mail.Service.connect(Service.java:386)
at javax.mail.Service.connect(Service.java:245)
at javax.mail.Service.connect(Service.java:194)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at JavaMailTest.main(JavaMailTest.java:65)

Any ideas on what the cause might be?