javamail mark gmail message as read

前端 未结 9 546
陌清茗
陌清茗 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:50

    One liner that will do it WITHOUT downloading the entire message:

    single message:

    folder.setFlags(new Message[] {message}, new Flags(Flags.Flag.SEEN), true);
    

    all messages:

    folder.setFlags(messages, new Flags(Flags.Flag.SEEN), true);
    

    Other methods of calling getContent() or creating a copy with new MimeMessage(original) cause the client to download the entire message, and creates a huge performance hit.

    Note that the inbox must be opened for READ_WRITE:

    folder.open(Folder.READ_WRITE);
    

提交回复
热议问题