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


                    Le Café Central de
Deva              

                                 
                                 ..... Deva blogs!!




 

 

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

  • Comments 3

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:

image

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
   3: 
   4: 
   5:   
   6: Set MapiSession = CreateObject("Mapi.Session") ' Create the MAPI Session.
   7:  
   8: MapiSession.Logon , , , False                  ' Log on to the session.
   9:  
  10: Set MapiMessage = MapiSession.Outbox.Messages.Add
  11:  
  12: With MapiMessage
  13:     .To = "testuser@contoso.com"
  14:     .Subject = "Test"
  15:     .Text = "Test"
  16:     .send showdialog:=True
  17: End With
  18:  
  19: MapiSession.Logoff
  20:  
  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
   3:           
   4: Set MapiSession = CreateObject("Outlook.Application") ' Create the MAPI Session.
   5: MapiSession.GetNamespace("MAPI").Logon , , , False
   6:                            
   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
  14:  
  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!!

  • 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.

  • 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

    ta!

  • 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

           objMAPISession.Logoff

       End If

       Set objMAPISession = Nothing

    End Sub

Page 1 of 1 (3 items)
Blog - Post Feedback Form(CAPTCHA)
Leave a Comment
  • Post