Search code examples
c#emailoutlookemail-attachmentsoutlook-2013

How to mark mail item as read?


I'm working on an App to save attached files in unread Outlook mail.

After that I want to mark the mail as read so it won't run on the same mails.

The mail is still marked as unread.

I wrote it like this:

    try
        {
            foreach (object collectionItem in inBoxItems)
            {
                newEmail = collectionItem as Outlook.MailItem;
                if (newEmail != null)
                {
                    if (newEmail.Attachments.Count > 0)
                    {
                       for (int i = 1; i <= newEmail.Attachments.Count; i++)
                        {

                            string filePath = Path.Combine(destination,newEmail.Attachments[i].FileName);
                            newEmail.Attachments[i].SaveAsFile(filePath);
                        }
                        NewMail.UnRead = false;
                        NewMail.Save();
                        flag = true;
                    }
                } 
            }
            if (flag == true) 
            {
                MessageBox.Show("saved!");
                flag = false;
            }
            else
                MessageBox.Show("not saved");
        }
        catch (Exception ex)
        {
            string errorInfo = (string)ex.Message.Substring(0, 11);
                MessageBox.Show(ex.Message);
        }

Solution

  • Change NewMail.UnRead = false; to newMail.UnRead = false;