VSTO Outlook Mark email as read

SSinhg 316 Reputation points
2022-09-30T06:32:44.223+00:00

Hi - I am using VSTO outlook 0365 & visual stidio 2019 for development.

I followed this code and its working fine to read unread email from specific folder.

But I am not able to mark the email as read once the attachment is saved to a folder

newEmail.UnRead = false;  

This won't work because this will mark everything as read

static void IterateMessages(Outlook.Folder folder)  
{  
    var fi = folder.Items;  
    if (fi != null)  
    {  
        foreach (Object item in fi)  
        {  
            Outlook.MailItem mi = (Outlook.MailItem)item;  
            var attachments = mi.Attachments;  
            if (attachments.Count != 0)  
            {  
                for (int i = 1; i <= mi.Attachments.Count; i++)  
                {  
                    Console.WriteLine("Attachment: " + mi.Attachments[i].FileName);  
                }  
            }  
        }  
    }  
}  


 **mi.Attachments[i].SaveAsFile(pathToSaveFile);**  

Appreciate any help..

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,098 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,057 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Oskar Shon 866 Reputation points
    2022-11-08T22:00:48.597+00:00

    I'm not coding in C but in VB works something like that

    Private Sub zItems_ItemAdd(ByVal Item As Object)  
        On Error Resume Next  
        Item.UnRead = False  
        Item.Save  
    End Sub  
    

    So you should save object after parameter change.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.