How can I mark a message as read in MailKit

René Pjengaard picture René Pjengaard · Aug 13, 2015 · Viewed 10.3k times · Source

I use MailKit to read some messages from a GMail Account. Works great, but when my application has read a message, I want to mark the message as read, and save that state to GMail. Is this possible with MailKit? I have not found anything about it yet.

Best regards René

Answer

jstedfast picture jstedfast · Aug 13, 2015

The way to mark messages as read using the IMAP protocol is to set the \Seen flag on the message(s).

To do this using MailKit, you will first need to know either the index(es) or the UID(s) of the messages that you would like to set the \Seen flag on. Once you have that information, you will want to call one of the AddFlags() methods on the ImapFolder. For example:

folder.AddFlags (uids, MessageFlags.Seen, true);

To mark messages as unread, you would remove the \Seen flag, like so:

folder.RemoveFlags (uids, MessageFlags.Seen, true);