I'm trying to use the Commons-Email API as an alternative to known JavaMail
to send emails in Java but there is a problem. The following Exception
is being released:
Exception in thread "main" java.lang.NoClassDefFoundError: javax / mail / Message at Main.main (Main.java:6)
The problem occurs on line 6 when I try to instantiate an object of class SimpleEmail
. Here is my code:
import org.apache.commons.mail.SimpleEmail;
public class Main {
public static void main(String[] args) {
try {
SimpleEmail email = new SimpleEmail(); // ops?! Aqui é lançada a Exception
email.setHostName("mail.foo.com");
email.setFrom("[email protected]", "rnxn") // remetente
.addTo("[email protected]", "Sr. Foo") // destinatário
.setMsg("Exception sendo lançada ao utilizar a API Commons-email") // corpo do email
.setSubject("StackOverflow"); // título
email.send(); // envio
} catch(Exception e){
System.out.println(e.getMessage());
}
}
}
I've successfully imported all of the .jar files that came in the download. Any solutions to the treatment of this problem?