If you want to access Outlook data (for example, by mail), you need to add the COM link to the Microsoft Outlook XX object library
For Outlook, you can use COM interoperability . Open the Add Link dialog box and select the .NET tab, and then add the link to the Microsoft.Office.Interop.Outlook assembly.
Then be sure to add the namespace "Microsoft.Office.Interop.Outlook" to your usage suggestions.
Now you can create an instance of the Outlook application object:
Microsoft.Office.Interop.Outlook.Application outlook; outlook = new Microsoft.Office.Interop.Outlook.Application();
Let the request in your inbox be completed:
MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox); IEnumerable<MailItem> mail = folder.Items.OfType<MailItem>().Where(m => m.Subject == "Test").Select(m => m);
You specify the folder you want to search as a parameter of the GetDefaultFolder (...) method. You can specify a folder other than the inbox.
- olFolderSentMail
- olFolderOutbox
- olFolderJunk
- ...
Check each possible value in MSDN:
Listing OlDefaultFolders
Stefan Cruysbergs has created an OutlookProvider component that acts as a wrapper for an Outlook application object. You can use LINQ to query this provider and retrieve data such as contacts, mail ... etc. Just download its code and check it out. That should be enough to get you started.
source share