Marking mails as read

Topics: Help requests
Apr 29, 2013 at 1:15 PM
Hi,
I'm not sure, if I'm doing something wrong, but i can't mark message as seen. Here is some code:

MessageCollection messages = imap.Folders[this.Folder].Search("UNSEEN", true);

foreach (Message message in messages)
                    {
                        message.AddFlag(ImapFlags.SEEN);
                        message.ProcessFlags();
                    }
Thanks for hlp :)
Coordinator
Apr 29, 2013 at 5:48 PM
Edited Apr 29, 2013 at 5:48 PM
Hi kzrysiej,

your code is fine, except one line - there is no need to call the ProcessFlags method. Simply make a call to AddFlag, should work without any problems.


Best regards,

Pavel Azanov
Apr 30, 2013 at 6:01 AM
Unfortunatly, it does't work. Here is th whole function:
public void WaitForMails(int interval)
        {
            while (true)
            {
                MessageCollection messages = imap.Folders[this.Folder].Search("UNSEEN", true);

                if (messages.Count > 0 && this.NewMailsReceived != null)
                {
                    this.NewMailsReceived(this, new MailReceivedEventArgs(messages, imap.Folders[this.Folder].Exists));

                    foreach (Message message in messages)
                    {
                        message.AddFlag(ImapFlags.SEEN);
                    }
                }


                Thread.Sleep(interval);
            }
        }
I think, maybe I'll just move messages to other folder.
Coordinator
Apr 30, 2013 at 6:33 PM
Hi,

as before, the code is fully correct.

Can you check if you can mark the messages as read using the sample application? (use the contextmenu on a message).

Is it also possible to provide some more details on your environment? Like which mail servers you're using (Google Mail etc.). This helps locating the issue.

Best regards,

Pavel Azanov