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
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.
Click the gear icon → Settings. On the General tab, scroll down to the Conversation view setting. Select Conversation view off.
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.
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.
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);
}
}
}
firstly try this
Folder folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With