在發送電子郵件時,我使用commons-email-1.3收到以下錯誤。
我已經下載並將外部jar添加到項目中。
請幫我解決這個問題!使用commons-email-1.3發送電子郵件時出錯
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"));
的錯誤消息是
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
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)
ERROE LINE:email.setAuthenticator(新DefaultAuthenticator ( 「本身份識別碼」, 「MYPWD」)); – H4SN 2013-02-25 08:08:32