Hello I am wondering if it is possible to send a search query to Outlook 2010 from my WinForms app. That is, not search the .PST file as I\'ve been searching around and finding,
If you want to access the Outlook data (mail for example) you have to add a COM reference to the Microsoft Outlook X.X Object library.
For Outlook you can use COM interop. Open the Add Reference dialog and select the .NET tab, then add a reference to the Microsoft.Office.Interop.Outlook assembly.
Afterwards don't forget to add the namespace "Microsoft.Office.Interop.Outlook" to your using clauses.
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's perform a query on your inbox:
MAPIFolder folder =
outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
IEnumerable mail =
folder.Items.OfType().Where(m => m.Subject == "Test").Select(m => m);
You specify the folder you want to search as a parameter for the GetDefaultFolder(...) method. You can specify other folder besides the inbox.
Check out each possible value on MSDN:
OlDefaultFolders Enumeration
Stefan Cruysbergs created an OutlookProvider component which acts as a wrapper for the Outlook application object. You can use LINQ to query this provider and retrieve data such as the contacts, mail...etc.. Just download his code and check it out. This should be enough to get you started.