How to mark mails as read using ImapX lib? C#

2k Views Asked by At

I'm using the free lib ImapX and I'm making an application to mark all my mails as receieved. Can anyone lend me a hand?

EDIT: Nevermind, found it out myself. They get marked as read when you process them.

2

There are 2 best solutions below

0
On

You need to add flag, which will help you to update status as seen.

  foreach (var mess in messages)
  {
   mess.SEEN = true; 
  }

Let me know if you are unable to change status.

0
On

First of all, if you're using the old ImapX library, I invite you to upgrade to ImapX 2. It's being constantly developed and supported. There is also sample code for all common operations.

The Process method of a message doesn't mark the message as read, it only downloads the whole message including attachments. In your case, if you call the Search method setting the second parameter to true, you don't have to call it for every single message.

To mark a message as read simply use the AddFlag method of Message:

ImapX.FolderCollection folders = imapclient.Folders;
ImapX.MessageCollection messages = imapclient.Folders["INBOX"].Search("UNSEEN", true); 
foreach (var mess in messages)
{
    mess.AddFlag(ImapFlags.SEEN); 
}