无法使用 javax.mail 从 google 获取草稿、垃圾邮件和垃圾文件夹中的电子邮件
我想从 gmail 的所有文件夹中获取电子邮件。 我从收件箱、已发送文件夹和其他文件夹中成功收到电子邮件。 但是,当我尝试从草稿、垃圾邮件和垃圾箱中获取它时,出现异常:
09:51:45,622 ERROR MailRetriever.[main]getNoFlaggedMails:142 - Can't get messages: javax.mail.MessagingException: connection failure
javax.mail.MessagingException: connection failure
at com.sun.mail.imap.IMAPStore.getProtocol(IMAPStore.java:742)
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:910)
at ua.com.stormlabs.gap.gmail.MailRetriever.getNoFlaggedMails(MailRetriever.java:133)
at ua.com.stormlabs.gap.gmail.GMailServiceProcessor.processFolder(GMailServiceProcessor.java:95)
at ua.com.stormlabs.gap.gmail.GMailServiceProcessor.start(GMailServiceProcessor.java:80)
at ua.com.stormlabs.gap.gmail.GMailGapApp.main(GMailGapApp.java:21)
这是用于检索邮件的代码:
Folder folder = imapSslStore.getFolder(folderName);
folder.open(Folder.READ_WRITE);
openedFolders.put(folderName, folder);
Flags searchFlags = new Flags(Flags.Flag.USER);
searchFlags.add(FLAG_PREFIX + READ_BY_GAP_FLAG);
Message[] messages = folder.search(new FlagTerm(searchFlags, false));
log.debug("Messages list retrieved: " + messages.length);
return messages;
我尝试打开但未成功的文件夹名称:
[Gmail]/Drafts
[Gmail]/Spam
[Gmail]/Trash
I want to get emails from all folders from gmail.
From inbox, sent and other folders I receive emails successfully.
But when I try to get it from Drafts, Spam and Trash I get an exception:
09:51:45,622 ERROR MailRetriever.[main]getNoFlaggedMails:142 - Can't get messages: javax.mail.MessagingException: connection failure
javax.mail.MessagingException: connection failure
at com.sun.mail.imap.IMAPStore.getProtocol(IMAPStore.java:742)
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:910)
at ua.com.stormlabs.gap.gmail.MailRetriever.getNoFlaggedMails(MailRetriever.java:133)
at ua.com.stormlabs.gap.gmail.GMailServiceProcessor.processFolder(GMailServiceProcessor.java:95)
at ua.com.stormlabs.gap.gmail.GMailServiceProcessor.start(GMailServiceProcessor.java:80)
at ua.com.stormlabs.gap.gmail.GMailGapApp.main(GMailGapApp.java:21)
This is code for retrieving mails:
Folder folder = imapSslStore.getFolder(folderName);
folder.open(Folder.READ_WRITE);
openedFolders.put(folderName, folder);
Flags searchFlags = new Flags(Flags.Flag.USER);
searchFlags.add(FLAG_PREFIX + READ_BY_GAP_FLAG);
Message[] messages = folder.search(new FlagTerm(searchFlags, false));
log.debug("Messages list retrieved: " + messages.length);
return messages;
Folder names I try to open unsuccessfully:
[Gmail]/Drafts
[Gmail]/Spam
[Gmail]/Trash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我发现我的 Gmail 帐户中的垃圾文件夹名为“[Google Mail]/Bin”等,而不是“Gmail]/Trash”。
我在英国,当我第一次打开 Gmail 帐户时,它确实是[电子邮件受保护] 不是我@gmail.com。
希望这有帮助。
I have found in my Gmail account the trash folder is named "[Google Mail]/Bin" etc. and not "Gmail]/Trash".
I am in the UK and when I first opened my Gmail account it was indeed [email protected] not me @gmail.com.
Hope this helps.
最简单的答案是草稿、垃圾邮件和垃圾邮件不是文件夹,而是 Google Mail 中的标签。我正在谷歌搜索来验证我的答案。
更新:经过一些谷歌搜索,我发现了 SO Post 其中指出
[Gmail]/*
文件夹是不可选择的文件夹。The simplest answer is that Draft, Spam and Trash are not folders but Labels in Google Mail. I am doing a Google search to validate my answer.
Update: After some Google search, I have found a SO Post which states that the
[Gmail]/*
folders are non-selectable folders.以下文件夹名称:
非常适合我。这是我经常使用 Javamail 读取垃圾邮件文件夹的代码:
The following folder name :
works perfectly for me. Here is my code I often use to read the spam folder using Javamail :
下面列出了一些默认的 GMAIL 文件夹名称。
Below listed are some of the default GMAIL folder names.