I have a requirement to retrieve unread mails from Gmail. I am using Java Mail API. By default, this API retrieves mails from the oldest to newest. But I need to retrieve re
I think this might help to access read/unread/recent mails change your variables according to your needs.
// search for all "unseen" messages
Flags seen = new Flags(Flags.Flag.SEEN);// try changing this SEEN to RECENT
// set it true or false for seen & unseen mail
FlagTerm unseenFlagTerm = new FlagTerm(seen, false)
Message messages[] = inbox.search(unseenFlagTerm);