Click here to Skip to main content
15,889,556 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
I have done coding to save attachment from outlook those are unread mail.

please find the below coding .It is working fine.

C#
string sp = @"D:\filescompare"; //Input directory to process comparision
//            ---Download attchment from outlook unread mail----
//Start
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Microsoft.Office.Interop.Outlook.MailItem newEmail = null;

try
{
    foreach (object collectionItem in myInbox.Items.Restrict("[unread]=true"))
    //foreach (object collectionItem in myInbox.Items.Restrict("[unread]=true"))
    {
        newEmail = collectionItem as Microsoft.Office.Interop.Outlook.MailItem;
        //newEmail = collectionItem as Microsoft.Office.Interop.Outlook.MailItem;

        if (newEmail != null)
        {
            if (newEmail.Attachments.Count > 0)
            {
                for (int j = 1; j <= newEmail.Attachments.Count; j++)
                {
                    newEmail.Attachments[j].SaveAsFile(sp + "\\" + newEmail.Attachments[j].FileName);
                }
            }
            else
            {
                Console.WriteLine();
            }
        }
    }
}
catch (System.Runtime.InteropServices.COMException ex)
{
    Console.WriteLine(ex.ToString());
}


But i want restrict if some body manually done unread ,for read mails.

Regards
Arul.R
Posted
Updated 10-Feb-15 17:42pm
v2
Comments
PIEBALDconsult 10-Feb-15 23:42pm    
Not sure. I wrote an Outlook macro to automatically download attachments, and one of the things I do is also set a flag, so I don't only look for unread I look for unflagged.

1 solution

I think PIEBALDConsult is correct - I used to use http://www.independentsoft.de/exchangewebservices/index.html[^], and Im pretty sure the 'property' they exposed was 'unflagged'

(I'm not affiliated with them, but I'll give their stuff a plug)

'g'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900