javamail mark gmail message as read

前端 未结 9 516
陌清茗
陌清茗 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 04:06

    The easiest way to do that is set the folder to be read or written into or from. Means like this...

        Folder inbox = null;
        inbox.open(Folder.READ_WRITE);      
    

    the Folder class should be imported.

    0 讨论(0)
  • 2021-01-31 04:08

    First of all, you can't mark a message as read if you are using a POP3 server - the POP3 protocol doesn't support that. However, the IMAP v4 protocol does.

    You might think the way to do this is to get the message, set the Flags.Flag.SEEN flag to true, and then call message.saveChanges(). Oddly, this is not the case.

    Instead, the JavaMail API Design Specification, Chapter 4, section "The Flags Class" states that the SEEN flag is implicitly set when the contents of a message are retrieved. So, to mark a message as read, you can use the following code:

    myImapFolder.open(Folder.READ_WRITE);
    myImapFolder.getMessage(myMsgID).getContent();
    myImapFolder.close(false);
    

    Or another way is to use the MimeMessage copy constructor, ie:

    MimeMessage source = (MimeMessage) folder.getMessage(1)
    MimeMessage copy = new MimeMessage(source);
    

    When you construct the copy, the seen flag is implicitly set for the message referred to by source.

    0 讨论(0)
  • 2021-01-31 04:10

    message.setFlag( Flag.SEEN,true ) give "cannot find symbol" message.setFlag( Flags.Flag.SEEN,true ) seems good.

    0 讨论(0)
提交回复
热议问题