问题描述
发送电子邮件时,我使用commons-email-1.3收到以下错误。
我已经下载并添加了外部jar到项目中。
请帮我解决这个问题!
While sending email I am getting the following errors using commons-email-1.3.
I have downloaded and added external jar's to the project.
Please help me fix this problem!
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"));
错误消息是
无法解析javax.mail.Authenticator类型。它是从所需的.class文件间接引用的。
来自类型Email的方法setAuthenticator(Authenticator)指的是缺少的类型Authenticator,在mypkg.mailtest.main(mailtest.java:13)
The type javax.mail.Authenticator cannot be resolved. It is indirectly referenced from required .class files
The method setAuthenticator(Authenticator) from the type Email refers to the missing type Authenticator at mypkg.mailtest.main(mailtest.java:13)
推荐答案
请从指定的链接下载罐子
Please download the jars from the specified links
这篇关于使用commons-email-1.3发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!