Search code examples
javajakarta-mailapache-commons

Problem sending mail with Apache Commons email


I'm trying to send a simple text email using commons email

    Email email = new SimpleEmail();
    email.setHostName("smtp.gmail.com");
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator("[email protected]", "123456"));
    email.setTLS(true);
    email.setFrom(from);
    email.setSubject(subject);
    email.setMsg(mesage);
    email.addTo("[email protected]");
    email.send();

But when I try to send the email ,I get this exception: enter image description here

Am I missing something?


Solution

  • Yes, you need the JavaMail API JAR as well (this is the javax.mail package).

    Commons Email sits on top of the JavaMail API and makes it a little less awful to use.