在使用 commons-email-1.3 发送电子邮件时,我收到以下错误。
我已经下载了外部 jar 并将其添加到项目中。
请帮我解决这个问题!
package mypkg;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.SimpleEmail;
public class sendingmail {
public static void main(String[] args) throws Exception {
Email email = new SimpleEmail();
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("myid","mypwd")); //Here is the error
email.setDebug(false);
email.setHostName("smtp.gmail.com");
email.setFrom("[email protected]");
email.setSubject("Hi");
email.setMsg("This is a test mail ... :-)");
email.addTo("[email protected]");
email.setTLS(true);
email.send();
System.out.println("Mail sent!");
}
}
给出错误的行是
email.setAuthenticator(new DefaultAuthenticator("myid","mypwd"));
错误信息是
线程“main”java.lang.Error 中出现异常:未解决的编译问题:
无法解析 javax.mail.Authenticator 类型。它是从所需的 .class 文件间接引用的
Email 类型中的 setAuthenticator(Authenticator) 方法引用了 mypkg.mailtest.main(mailtest.java:13) 中缺少的 Authenticator 类型
请从指定链接下载jar包
激活JAR
Java 邮件 jar
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)