嗨,我用下面的代码发送电子邮件:
public static void sendEmail(String from, String to, String password) {
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator(from, password));
email.setSSLOnConnect(true);
email.setSubject("Plain mail");
email.setMsg("test");
email.addTo(to);
email.send();
}现在,当我用“普通”gmail地址调用这个函数时,它可以工作:
sendMail("me@gmail.com","friend@gmail.com", "my-password");所以,上面的工作。但是,当我试图迁移到Gmail,并创建一个电子邮件地址"me@mycompany.com“(与Gmail挂钩)时,我会得到一个身份验证错误:
sendMail("me@mycompany.com","friend@gmail.com", "my-new-password");给我这个错误:
javax.mail.AuthenticationFailedException:
<https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsb...ZlTLN2wQG4>
Please log in via your web browser and then try again.我怀疑我需要在我的谷歌应用程序控制台设置一些东西,但我甚至不知道从哪里开始寻找信息。
有人能帮忙吗?谢谢。
发布于 2015-12-09 00:37:51
这个答案来自一个类似的所以问题这里。
问题在于允许不太安全的应用程序访问您的帐户。单击以下链接https://www.google.com/settings/security/lesssecureapps并禁用安全设置。有关更多信息,您可以阅读此这里。
祝好运!
https://stackoverflow.com/questions/34162254
复制相似问题