javamail mark gmail message as read

前端 未结 9 551
陌清茗
陌清茗 2021-01-31 03:13

Note: added after answer: Thanks.. Yeah I had tried the Flag.SEEN to true and saveChanges.. I also had read getContent marks it read. I tried using it in the for statement that

9条回答
  •  庸人自扰
    2021-01-31 03:57

    If you are using a for loop to read or check a mail one by one, the code can be as follows to mark a gmail message as read:

        Message[] unreadMessages = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false));
                for (int q = 0; q < unreadMessages.length; q++) {
    
                  unreadMessages[q].setFlag(Flag.SEEN, true);
    
                }
    

    What this code does is that it makes it unread one by one.

    And also folder/inbox needs to be READ_WRITE, instead of READ_ONLY:

    folder.open(Folder.READ_WRITE);
    

提交回复
热议问题