简体   繁体   English

Gmail也会从已发送邮件中提取邮件

[英]Gmail fetching mails from Sent items as well

I have the following code to connect to an inbox of a mail server: 我有以下代码连接到邮件服务器的收件箱:

Store popStore = popSession.getStore("pop3");
popStore.connect(address, userName, password);
Folder  inboxFolder = popStore.getFolder("Inbox");

Post this i check for new mails. 发布这个我检查新邮件。 Now when I connect to Gmail, I am getting mails from Sent Items as well when actually it is supposed to be only from the Inbox folder. 现在,当我连接到Gmail时,我也会收到来自已发送邮件的邮件,而实际上它应该只来自收件箱文件夹。 With Yahoo this is working fine. 雅虎这个工作正常。

Any Idea what can be causing this issue in Gmail? 任何想法可以在Gmail中导致此问题?

Edit: I have tried with INBOX as well and the result is the same 编辑:我也试过INBOX,结果是一样的

Following is a code snippet. 以下是代码段。 When I checked with gmail, there is no overlap between inbox and sent mail. 当我使用gmail检查时,收件箱和已发送邮件之间没有重叠。 (This should have been a comment, posting as answer for formatting) (这应该是评论,发布作为格式的答案)

javax.mail.Folder[] folders = store.getDefaultFolder().list("*");
for (javax.mail.Folder folder : folders) {
    if ((folder.getType() & javax.mail.Folder.HOLDS_MESSAGES) != 0) {
        if (folder.getFullName().equalsIgnoreCase("[Gmail]/Sent Mail") 
                || folder.getFullName().equalsIgnoreCase("Inbox")) {
            System.out.println(folder.getFullName() + ": " + folder.getMessageCount());
            folder.open(Folder.READ_ONLY);
            for (Message m : folder.getMessages(
                               folder.getMessageCount() - 5, 
                               folder.getMessageCount())) {
                System.out.println("m.getSubject() = " + m.getSubject());
            }
            folder.close(true);
        }
    }
}

firstly try this 首先尝试这个

Folder folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
folder.open(Folder.READ_WRITE);

Interesting issue. 有趣的问题。 I did a little research and found this post in which Google says: 我做了一些研究,发现这篇帖子谷歌说:

When you enable POP, all messages are downloaded to your client, except for Spam, Trash, and Chats. 启用POP后,除垃圾邮件,已删除垃圾邮件和聊天记录外,所有邮件都会下载到您的客户端。 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. 如果您不希望从Web界面发送的邮件下载到您的邮件客户端的收件箱,我们建议您在客户端中创建一个过滤器。

To create a filter by sender, you can do this: 要按发件人创建过滤器,您可以执行以下操作:

String filter = "Not([SenderEmailAddress] = 'XXXXX@gmail.com')";
Items inboxItems = inboxFolder.Items.Restrict(filter);

where XXXXX@gmail.com is your email address. 其中XXXXX@gmail.com是您的电子邮件地址。 This filter will give you only the items which are sent by someone other than yourself. 此过滤器仅为您提供由您以外的人发送的项目。 Additionally, the Restrict method can be replaced with Find , but Restrict will be much faster for larger datasets. 此外, Restrict方法可以替换为Find ,但对于较大的数据集, Restrict会快得多。

when you communicate through mail using reply or reply to all in gmail it will considered as inbox mail. 当您使用回复或回复所有在Gmail中通过邮件进行通信时,它将被视为收件箱邮件。 Because it is conversation view. 因为它是会话视图。 so that your sent mail is also an inbox mail. 这样您发送的邮件也是收件箱邮件。 so you will get that mails in your messages. 所以你会在邮件中收到邮件。

Read this official google answer. 阅读官方谷歌答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM