java 请通过您的网络浏览器登录:https://support.google.com/mail/accounts/answer/78754(失败)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35377560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure)
提问by Matan Tubul
I am trying to connect to my mail box using the java mail api based on imap protocol. I check and for sure I inserting the correct parameters. This is the following exception that I got:
我正在尝试使用基于 imap 协议的 java 邮件 api 连接到我的邮箱。我检查并确定我插入了正确的参数。这是我得到的以下异常:
[ALERT] Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754(Failure)
[提醒] 请通过您的网络浏览器登录:https: //support.google.com/mail/accounts/answer/78754(失败)
I do not know why it is happens in addition I enabled the imap option in my gmail account settings.
我不知道为什么会发生这种情况,另外我在我的 gmail 帐户设置中启用了 imap 选项。
Ihis is my code:
我是我的代码:
Properties protocol = new Properties();
protocol.setProperty("mail.store.protocol", "imaps");
try{
Session session = Session.getInstance(protocol, null);
Store store = session.getStore();
String host = prop.getProperty("host");
String email = prop.getProperty("username");
String password = prop.getProperty("password");
store.connect(host, email, password);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
int messageCount = inbox.getMessageCount();
model.addAttribute("msg","number of mails"+" "+messageCount);
Message[] messages = inbox.getMessages();
PrintWriter writer = new PrintWriter(username+".txt", "UTF-8");
for(int i=0;i<messageCount || prop.getProperty("status").equals(status.RUNNING.toString()) ;i++ ){
model.addAttribute("msg","Reading Mails");
Multipart mp = (Multipart) messages[i].getContent();
BodyPart bp = mp.getBodyPart(0);
writer.println("From:"+ messages[i].getFrom()+" "+"Subject:"+messages[i].getSubject()+" "+"Message:"+bp.getContent());
prop = loadProperties(username+".properties");
}
writer.close();
inbox.close(true);
store.close();
}catch (Exception e){
model.addAttribute("msg","Exception:"+e.getMessage());
}
采纳答案by Matan Tubul
after searching I found that I need to change the host name to imap.googlemail.com
搜索后我发现我需要将主机名更改为 imap.googlemail.com
the following code was changed:
以下代码已更改:
mail.store.protocol
changed to:
变成:
imap.googlemail.com
回答by Abhishek Gupta
I would recommend you doing the following:
我建议您执行以下操作:
- Just enable 2-step verificationon your account.
- Then generate one App-Specific-Passwordand us that to connect instead of your original password.
- 只需在您的帐户上启用两步验证即可。
- 然后生成一个App-Specific-Password和我们连接,而不是您的原始密码。