Counting the number of Emails in the Gmail INBOX(计算 Gmail 收件箱中的电子邮件数量)
问题描述
这是计算 gmail
收件箱中邮件数量的代码.
This is the code that counts the number of mails in the gmail
inbox.
Properties props = new Properties();
props.put("mail.pop3.host" , "pop.gmail.com");
props.put("mail.pop3.user" , "username");
props.put("mail.pop3.socketFactory" , 995 );
props.put("mail.pop3.socketFactory.class" , "javax.net.ssl.SSLSocketFactory" );
props.put("mail.pop3.port" , 995);
Session session = Session.getDefaultInstance(props , new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication( "username" , "password");
}
});
try {
Store store = session.getStore("pop3");
store.connect("pop.gmail.com" , "username" , "password");
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.HOLDS_MESSAGES);
int count = fldr.getMessageCount();
System.out.println(count);
} catch(Exception exc) {
System.out.println(exc + " error");
}
我得到的计数等于 7
,但我应该得到 3
,因为我的收件箱中只有 3 条消息.
I get the count equal to 7
but i should get 3
because i have only 3 messages in the inbox.
推荐答案
在 GMAIL POP3 设置中,您应该只对当前收到的电子邮件启用 POP 访问,这是标准的 GMAIL 行为.
In GMAIL POP3 settings you should enable POP access only for the emails received from the current moment, it's standard GMAIL behavior.
启用 POP 后,所有邮件都会下载到您的客户端,但垃圾邮件、垃圾邮件和聊天邮件除外.如果您不希望从 Web 界面发送的消息下载到邮件客户端的收件箱,我们建议在您的客户端中创建一个过滤器.您可能需要联系您的邮件客户端的客户服务部门,了解如何对下载的邮件进行分类.
When you enable POP, all messages are downloaded to your client, except for Spam, Trash, and Chats. If you don't want messages that you send from the web interface downloaded to your mail client's inbox, we suggest creating a filter within your client. You may want to contact your mail client's customer service department for instructions on how to categorize downloaded messages.
查看 GMAIL 问题排查文章
GMAIL 中的 AFAIK 选择性同步仅适用于 IMAP 协议.
AFAIK selective sync in GMAIL is only possible with IMAP protocol.
这篇关于计算 Gmail 收件箱中的电子邮件数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:计算 Gmail 收件箱中的电子邮件数量


- Eclipse 的最佳 XML 编辑器 2022-01-01
- 获取数字的最后一位 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 转换 ldap 日期 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01