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 收件箱中的电子邮件数量
基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01