Accessing Outlook
The first requirement is to be able to access Outlook. For those with Outlook/Office 2003, you should run the office install and choose .NET Programmability Support. For Office XP, you can download the Interop assemblies from http://support.microsoft.com/default.aspx/kb/328912?.
The appropriate assemblies will then be installed in the GAC, and you can then add a reference from your Visual Studio project to Microsoft.Office.Interop.Outlook.dll.
Add an appropriate using clause:
using Outlook = Microsoft.Office.Interop.Outlook;
Then you should be able to instantiate an Outlook object and make requests of it:
Outlook.Application app = new Outlook.ApplicationClass();
Outlook.NameSpace NS = app.GetNamespace("MAPI");
Outlook.MAPIFolder inboxFld = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
This will give you access to inboxFld, which will allow you to iterate through the contents of the inbox! You can also change this to iterate through notes, or through calendar entries, tasks, etc. as you want.
For example, to iterate through your mail you can do:
foreach(Outlook.MailItem t in inboxFld.Items)
{
Console.WriteLine(t.Subject);
}
Now you can search for your particular mail using t.Subject and
foreach(Outlook.Attachment Atmt in t.Attachments){
'save the attachment to some filename, just for ex., c:\test.doc
Atmt.SaveAsFile "C:\test.doc"
}
There's a sample VB code in one of our previous post, it can also help you out in using the same in your c# code.
http://www.eggheadcafe.com/community/aspnet/8/10011416/asking-word-to-behave-wit.aspx
http://www.outlookcode.com/codedetail.aspx?id=1039