0

I was trying to use Apache Commons library to send email. But it gives me an error saying

"the type of setAuthenticator(Authenticator) is erroneous" in email.setAuthenticator function.

Here is my code. I am not sure why I get this error.

public static void sendSimpleMail() throws Exception {
    Email email = new SimpleEmail();
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator("me@gmail.com","my gmail password"));
    email.setDebug(false);
    email.setHostName("smtp.gmail.com");
    email.setFrom("me@gmail.com");
    email.setSubject("Hi");
    email.setMsg("This is a test mail ... :-)");
    email.addTo("you@gmail.com");
    email.setTLS(true);
    email.send();
    System.out.println("Mail sent!");
}
djv
  • 15,168
  • 7
  • 48
  • 72
  • You are getting the error on the line `email.setAuthenticator(new DefaultAuthenticator("me@gmail.com","my gmail password")); email.setDebug(false);`, correct? – djv Jan 22 '15 at 16:54
  • possible duplicate of [Error in sending email using commons-email-1.3](http://stackoverflow.com/questions/15062549/error-in-sending-email-using-commons-email-1-3) – djv Jan 22 '15 at 17:00

1 Answers1

0

You can try using a different method for the authentication data which receives username and password directly, then the Authenticator will be handled internally by commons-email:

email.setAuthentication("me@gmail.com","my gmail password")
centic
  • 15,565
  • 9
  • 68
  • 125