Outlook 2010: Migrating CDO based application to Outlook Object Model(OOM) library

Recently one of my developer customer migrated from Outlook 2003 to 2010. He tried running the custom application (uses CDO & Outlook 2003) in Outlook 2010. It throws the error “ActiveX component can’t create object”. 

Using the following test sample, I can reproduce the exact issue at my end:


As you know, Microsoft Outlook 2010 includes many architectural changes to the client-side MAPI subsystem. Of particular concern are scenarios in which Outlook is configured to use multiple Exchange accounts. Also, CDO 1.2.1 is a 32-bit client library and will not operate with 64-bit Outlook 2010. Given all these factors, CDO 1.2.1 is not supported for use with Outlook 2010 and we don’t recommend its usage with Outlook 2010. As updated earlier, in Outlook 2010 you need to re-write/migrate the code base referencing CDO to Outlook Object Model or MAPI, messaging libraries which ever suits you.  So the programs/custom applications that use CDO should be re-designed to use other Application Programming Interfaces (APIs) instead of CDO.

Starting with Outlook 2007, the Outlook object model was greatly expanded to provide functionality that was previously available only by using CDO 1.2.1. The Outlook 2010 object model includes some new features to expand on this more. For example, the Outlook 2010 object model has new functionality to operate correctly with multiple Exchange accounts. The Outlook object model also works for both 32-bit and 64-bit versions of Outlook. Developers should use the Outlook 2010 object model instead of CDO 1.2.1. Also, developers can still use Extended MAPI (which requires unmanaged C++) in some scenarios where CDO was required. However, if it is possible, we generally recommend that the Outlook object model be used instead of Extended MAPI.

In this post, we will take the above code sample and will show how you can migrate/re-write the CDO based application to Outlook Object Model library.

CDO sample – created in Outlook 2003:

   1: Dim MapiSession As Object
   2: Dim MapiMessage As Object
   6: Set MapiSession = CreateObject("Mapi.Session") ' Create the MAPI Session.
   8: MapiSession.Logon , , , False                  ' Log on to the session.
  10: Set MapiMessage = MapiSession.Outbox.Messages.Add
  12: With MapiMessage
  13:     .To = "testuser@contoso.com"
  14:     .Subject = "Test"
  15:     .Text = "Test"
  16:     .send showdialog:=True
  17: End With
  19: MapiSession.Logoff
  21: Set MapiSession = Nothing  ' Clear the object variable.
  • In order to start with, we will do it from the declaration section – you can see the CDO/OOM migrated sample and notice the changes.
  • In CDO code, it’s specified as Set MapiSession = CreateObject(“Mapi.Session”). When it comes to Outlook Object Model, then it should be converted as, Set MapiSession = CreateObject("Outlook.Application")
  • Now, we will try the next line, which is doing logon() call. In CDO, it’s MapiSession.Logon , , ,False. In OOM, it’s you need to add GetNamespace, so MapiSession.GetNamespace("MAPI").Logon , , , False
  • Next line in CDO points that a new mail item will be created in Outbox folder. In OOM, it need to be simplified: MapiSession.CreateItem(olMailItem).
    • Please note I haven’t used outbox folder like, MapiSession.GetNamespace("MAPI").GetDefaultFolder(olFolderOutbox)
  • I don’t see much changes when you specify the values for MapiMessage, except for .Send (CDO) – just needs to be trimmed as .Send(in OOM)

Once you done with migration, the OOM code (created in Outlook 2010) will look like the below:

   1: Dim MapiSession As Outlook.Application
   2: Dim MapiMessage As Outlook.MailItem
   4: Set MapiSession = CreateObject("Outlook.Application") ' Create the MAPI Session.
   5: MapiSession.GetNamespace("MAPI").Logon , , , False
   7: Set MapiMessage = MapiSession.CreateItem(olMailItem)
   8: With MapiMessage
   9:     .To = "testuser@contoso.com"
  10:     .Subject = "Test"
  11:     .Body = "Test"
  12:     .Send
  13: End With
  15: Set MapiSession = Nothing

Please note: Microsoft product support can help developer customers migrate custom programs from using CDO 1.2.1 to using other APIs. However, Microsoft will not provide support for any scenarios in which CDO 1.2.1 is used with Outlook 2010.

Happy programming!!

Comments (5)
  1. socrates says:

    Hey Dev guy, Where were you till the time. I just saw this article; Nice one, earlier i struggled this similar CDO application. Later when i learnt that there is no support on this. Now i got a way to move ahead. Nice one, bro.

  2. Martyn says:

    Is it possible to connect to another user's mailbox using this code with Windows 7 and Office 2010? It worked with XP and 2010 but now we get invalid parameter messages.

    strMAPI = strExchangeSvr & vbLf & strUserName

    objMAPISession.Logon "", "", False, True, 0, False, strMAPI


  3. Vikas Tyagi says:

    Hi Guys,

    i used the below code to automate my out of office  but this is giving object required error. could someone please assist me on this as its a bit urgent.

    Private Sub Application_Quit()

       Dim objMAPISession As Outlook.Application

       Dim StartDate As Date

       Set objReminders = Nothing

       If MsgBox("Would you like to turn the Out of Office Assistant on?", vbYesNo, "Activate Out of Office Assistant") = vbYes Then

           Set objMAPISession = CreateObject("Outlook.Application")

           objMAPISession.Logon , , , False

           objMAPISession.OutOfOffice = True

           If objMAPISession.OutOfOffice = True Then

               StartDate = CDate(InputBox("Enter the date, " & "in the format: mm/dd/yyyy"))

               objMAPISession.OutOfOfficeText = "Hi,"

           End If


       End If

       Set objMAPISession = Nothing

    End Sub

  4. Dileep says:

    Hi Vikas Tyagi,

    Pleae let me know is your issue got resolved or not. Even i am facing the same issue.

  5. Deva [MSFT] says:

    @Vikas – If you're using Outlook Object Model API then, the Out of Office settings are not directly exposed. You can read the state of by using PropertyAcessor & PR_OOF_STATE Property. Apart from that, you can try accessing it with MAPI, EWS API's.

Comments are closed.

Skip to main content