Migrating code dependent on CDO 1.2.1 to use the Outlook Object Model RRS feed

  • Question

  • I'm working with a system which has an unusual way of handling certain types of email. Messages which have been sent to a specific address get placed on a folder in the file system as raw .eml files. We have a service (on the mail server) which scans this folder periodically, parses the email, performs some business logic depending on the message (attachments, from/to and body), and then passes the modified message back to Exchange. 

    This currently uses Collaboration Data Objects to load and parse the email, like so:

            //Called once per file
            private static void readMail(string filePath)
                CDO.Message message = new CDO.MessageClass();
                ADODB.Stream stream = new ADODB.StreamClass();
                message.DataSource.OpenObject(stream, "_Stream");
                CDO.IBodyParts attachments = message.Attachments;
                for (int i = 0; i < attachments.Count - 1; i++)
                    CDO.IBodyPart attachment = attachments[i];
                    // Do something with each attachment
                string htmlBody = message.HTMLBody;
                string messageFrom = message.From;
                string messageto = message.To;
                // Do something with mail data

    However, versions of exchange and outlook are going to be upgraded, and these updated versions do not support CDO ( 

    The linked KB article suggests that I should be able to implement the above functionality using the Outlook Object Model. After some digging I've been able to convert most of the complex parts, but I'm completely stuck on the above snippit. I cannot figure out how to use the object model to open a raw email, and parse it into something I can use.

    Currently the service is written in C#, but if the only way to access the functions I need is through unmanaged code (C++), rewriting the service would be an option.

    Tuesday, April 2, 2013 10:21 AM


All replies

  • If you are using C++ or Delphi and Outlook is installed, you can use IConverterSession MIME converter used by Outlook. IConverterSession  is not available if only the standalone version of MAPI is installed.

    If using Redemption is an option, you can use its RDO family of objects and RDOMail.Import in particular to import the EML files.

    How do you copy the data back to Exchange? What API are you using?

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Tuesday, April 2, 2013 1:32 PM
  • Thanks for the info about IConverterSession, I'll look into that for my parsing needs.

    A commercial library is unfortunately not an option - It would make things much easier.

    Exchange Web Services are used to sent the mail back to exchange. I'm unsure if that's possible using an unmanaged language, but I should be able to work something out.

    Friday, April 5, 2013 8:20 AM
  • If you only need to parse MIME messages in .Net, I used Lumisoft.Net parser before -

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, April 5, 2013 2:06 PM