Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. With Yahoo this is working fine.

Any Idea what can be causing this issue in Gmail?

Edit: I have tried with INBOX as well and the result is the same

like image 526
rajesh Avatar asked Jul 15 '13 09:07

rajesh


People also ask

Why are my sent emails showing in my inbox Gmail?

If you have a Gmail filter set up to send all emails from yourself to your Inbox folder, then that's why sent email show up in the Inbox. Another possible cause is that you have all emails from yourself set up to be marked as starred emails while having all starred messages included in your Primary folder.

How do I stop my sent emails from showing in my Gmail inbox?

Click the gear icon → Settings. On the General tab, scroll down to the Conversation view setting. Select Conversation view off.

Why are my emails not showing as sent?

The most likely cause of an email not appearing in the Sent folder is that it wasn't sent in the first place. You may well have hit the Send icon, but for some reason or another – perhaps shutting down the email app or the computer before the message had actually been sent – the message never left your system.


4 Answers

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. 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.

To create a filter by sender, you can do this:

String filter = "Not([SenderEmailAddress] = '[email protected]')";
Items inboxItems = inboxFolder.Items.Restrict(filter);

where [email protected] is your email address. 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.

like image 57
Luke Willis Avatar answered Oct 02 '22 06:10

Luke Willis


Following is a code snippet. When I checked with gmail, there is no overlap between inbox and sent mail. (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);
        }
    }
}
like image 41
Jayan Avatar answered Oct 02 '22 06:10

Jayan


firstly try this

Folder folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
like image 21
shreyansh jogi Avatar answered Oct 02 '22 07:10

shreyansh jogi


when you communicate through mail using reply or reply to all in gmail it will considered as inbox mail. 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.

like image 43
Armaan Stranger Avatar answered Oct 02 '22 07:10

Armaan Stranger