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.
Asked
Active
Viewed 1.5k times
1 Answers
71
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);

jstedfast
- 35,744
- 5
- 97
- 110
-
The RemoveFlags function doesn't seem to have any effect. Could you please modify your answer to include the connection to the server too? – Amged Rustom Jan 04 '16 at 13:02
-
9Make sure that you open the folder in `FolderAccess.ReadWrite` mode. – jstedfast Jan 04 '16 at 14:10
-
Thanks. Works now perfectly. – Amged Rustom Jan 05 '16 at 05:57
-
Is there way to do it having `MimeMessage` only without knowing in what folder it is? – Powercoder Dec 22 '18 at 17:50
-
No, there's no way to set the flags without knowing the folder. – jstedfast Dec 23 '18 at 02:59