0
 try {
        Email email = new SimpleEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("***@gmail.com", "*********"));
        email.setSSL(true);
        email.setFrom("*******@gmail.com");
        email.setSubject("TestMail");
        email.setMsg("This is a test mail ... :-)");
        email.addTo("*****@gmail.com");
        email.setTLS(true);
        email.send();
    } catch (Exception e) {
        e.printStackTrace();
    }

This is the code I've used and this is the print stack trace

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.googlemail.com:587
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at Main.main(Main.java:28)
Caused by: javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:306)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at javax.mail.Transport.send0(Transport.java:168)
    at javax.mail.Transport.send(Transport.java:98)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)

can someone tell me what's wrong with my code??

Aruna Karunarathna
  • 981
  • 2
  • 23
  • 55
  • Possible duplicate http://stackoverflow.com/questions/2047942/how-to-resovle-javax-mail-authenticationfailedexception-issue – David Gelhar Apr 26 '12 at 18:18

1 Answers1

0

Did you try on port 465 ?

And with email.setSSLOnConnect(true); instead of setSSL and setTLS ?

Snicolas
  • 37,840
  • 15
  • 114
  • 173