All I want to do is send an email in Java. Here is the example I found:
import org.apache.commons.mail.SimpleEmail;
public class Email {
public static void sendMessage(String emailaddress, String subject, String body) {
try {
SimpleEmail email = new SimpleEmail();
email.setHostName("valid ip address here");
email.addTo(emailaddress);
email.setFrom("noreply@example.com", "No reply");
email.setSubject(subject);
email.setMsg(body);
email.send();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I immediately get the following exception on the SimpleEmail email = new SimpleEmail(); line:
java.lang.ClassNotFoundException: org.apache.commons.mail.SimpleEmail
I have the following JAR in my project (using Netbeans):
commons-email-1.2.jar
What am I doing wrong?
Thanks.
Not sure why SimpleEmail didn’t work. But this did:
Thanks for the suggestions.