计算 Gmail 收件箱中的电子邮件数量 [英] Counting the number of Emails in the Gmail INBOX

查看:69
本文介绍了计算 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 收件箱中的电子邮件数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆