JavaMail reading recent unread mails using IMAP

前端 未结 4 1322
挽巷
挽巷 2020-12-10 02:46

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

4条回答
  •  隐瞒了意图╮
    2020-12-10 03:15

    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);
    

提交回复
热议问题