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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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..
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.