使用Apache Commons电子邮件库在Java中发送电子邮件时发生身份验证错误
我试图使用ApacheCommons库发送电子邮件。但这给了我一个错误的说法
"the type of setAuthenticator(Authenticator) is erroneous" in email.setAuthenticator function.
这是我的密码。我不知道为什么会出现这个错误
public static void sendSimpleMail() throws Exception {
Email email = new SimpleEmail();
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("me@gmail.com","my gmail password"));
email.setDebug(false);
email.setHostName("smtp.gmail.com");
email.setFrom("me@gmail.com");
email.setSubject("Hi");
email.setMsg("This is a test mail ... :-)");
email.addTo("you@gmail.com");
email.setTLS(true);
email.send();
System.out.println("Mail sent!");
}
# 1 楼答案
您可以尝试对直接接收用户名和密码的身份验证数据使用不同的方法,然后将通过commons电子邮件在内部处理身份验证者: