简体   繁体   English

Apache Commons Email使用“普通gmail”,而不使用“ Gmail for work”吗?

[英]Apache Commons Email work with “normal gmail”, but not “Gmail for work”?

Hi I'm using the following code to send email: 嗨,我正在使用以下代码发送电子邮件:

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();
}

Now, it works when I'm calling this function with my "normal" gmail address: 现在,当我使用“普通” Gmail地址调用此函数时,它可以工作:

sendMail("me@gmail.com","friend@gmail.com", "my-password");

So the above works. 因此上述工作。 But when I'm trying to migrate to Gmail for Business, and create an email address "me@mycompany.com" (which is hooked to Gmail), I get an authentication error: 但是,当我尝试迁移到Gmail for Business,并创建一个电子邮件地址“ me@mycompany.com”(已挂接到Gmail)时,出现验证错误:

sendMail("me@mycompany.com","friend@gmail.com", "my-new-password");

Gives me this error: 给我这个错误:

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.

I suspect I need to set something in my Google Apps console, but I'm not even sure where to start looking for the info. 我怀疑我需要在Google Apps控制台中进行设置,但是我什至不知道从哪里开始查找信息。

Can anybody help? 有人可以帮忙吗? Thanks. 谢谢。

This answer is coming from a similar SO question here . 这个答案是从类似来得这么质疑这里

The issue is due to allowing less secure apps to access your account. 该问题是由于允许安全性较差的应用访问您的帐户而引起的。 Click the following link https://www.google.com/settings/security/lesssecureapps and disable security setting. 点击以下链接https://www.google.com/settings/security/lesssecureapps并禁用安全设置。 For more information you can read this here . 有关更多信息,您可以在这里阅读。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM