C# code to retrieve mail messages from MS Exchange server

I would like to have a C# app  that can go to my Outlook mailbox on the MS Exhange server and retrieve the mail messages, and save them as files so I can parse the body of the message for embedded data.
cmh_rwhelanAsked:
Who is Participating?
 
StephanConnect With a Mentor Lead Software EngineerCommented:
0
 
nipunuConnect With a Mentor Commented:
this works only in your outlook

using Outlook = Microsoft.Office.Interop.Outlook; //you need to add the Microsoft Office 11.0 Object Library to use this. mine is version 11 you might have an older or later version.

 

Outlook.Application outlook = new Outlook.ApplicationClass();
Outlook.NameSpace ns = outlook.GetNamespace("Mapi");

        object _missing = Type.Missing;
        ns.Logon(_missing, _missing, false, true);


        Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
               
        int unread = inbox.UnReadItemCount;

                foreach (Outlook.MailItem mail in inbox.Items)
                {
                    string s = mail.Subject;
                    //get what you want
                }
0
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
0
 
cmh_rwhelanAuthor Commented:
I will continue to p[ost here as the solution unfolds and I have a working app.

Thanks
0
All Courses

From novice to tech pro — start learning today.