1
我想發送一封電子郵件與commons api,但是,我錯了!Java電子郵件與共享郵件
這是共享指南的例子,但是,我不能在這裏發..
public class Emailsss {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws EmailException, MalformedURLException {
// TODO code application logic here
// Create the email message
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "mypw"));
email.setSSLOnConnect(true);
email.setFrom("username");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("to");
URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
String cid = email.embed(url, "Apache logo");
email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");
email.setTextMsg("Your email client does not support HTML messages");
// send the email
email.send();
}
}
這是我的錯誤:
Exception in thread "main" java.lang.NoSuchMethodError:
javax.mail.internet.MimeBodyPart.setText(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
at org.apache.commons.mail.HtmlEmail.build(HtmlEmail.java:581)
at org.apache.commons.mail.HtmlEmail.buildMimeMessage(HtmlEmail.java:519)
at org.apache.commons.mail.Email.send(Email.java:1436)
at emailsss.Emailsss.main(Emailsss.java:46)
Java Result: 1
你是如何構建它的?其他的jar是類路徑的一部分嗎? – 2013-11-21 07:00:43
我收到了mail.jar,activation.jar,commons.jar ...只有@MichaelT – DougBaltazar
看起來像你缺少一個jar文件http://repo1.maven.org/maven2/javax/mail/mail/1.4/mail -1.4.jar –