Moving from CDO to the Outlook Object Model
In Dovetail Agent, there has been support for a long time to integrate Microsoft Outlook into the email functionality. In the past this has been done by using Collaboration Data Objects (CDO), which is a 32-bit client library that provides access to Outlook-compatible objects through a COM-based API.
As customers (and Dovetail Software employees) upgraded to Office 2010 (x64), the Outlook integration solution that tried to load the 32-bit CDO ActiveX controls or DLLs did not work. The resolution for this issue was to migrate Dovetail Agent from using CDO to use the Outlook Object Model (OOM).
Opening the Session with Outlook
The first step was to get access to the Outlook Object Model (OOM). In Dovetail Agent 4.5, the method for opening a session was to create a MAPI session from CDO, and then log on using the default profile of the current user as shown here:
var objSession = new ActiveXObject("MAPI.Session");
objSession.Logon(”,”,true,false);
To update this for the Outlook Object Model, the same code changed slightly:
var outlook = new ActiveXObject("Outlook.Application");
var objSession = outlook.Session;
objSession.Logon(”,”,true,false);
The change is subtle, with just a different target for the ActiveX Object, but the biggest difference is creating a session on a separate line.
Creating the Email
The next step is to create a new mail item. Again, this is slightly different. The CDO version uses the session’s outbox and sets the text of the email:
var objMessage = objSession.Outbox.Messages.Add;
objMessage.Body = document.getElementById(‘message’).value;
and the OOM version creates the mail item directly and uses the Body property for the email content:
var objMessage = outlook.CreateItem(0);
objMessage.Body = document.getElementById(‘message’).value;
Adding Attachments to the Email
Adding attachments takes a little bit more effort to get it up to date. The old version creates an attachment and sets its properties:
var objAttachments = objMessage.Attachments;
var objAttachment = objAttachments.Add;
var cdoFileData = 1;
objAttachment.Type = cdoFileData;
objAttachment.ReadFromFile(file_name_path);
objAttachment.Source = file_name_path;
The OOM version creates an attachment using a method call:
var objAttachments = objMessage.Attachments;
var outlookAttachmentType = 1;
objAttachments.Add(file_name_path, outlookAttachmentType);
Validating the Email Recipients
The CDO version uses the Resolve method:
objRecipients.Resolve;
The OOM version changes to the ResolveAll method::
objRecipients.ResolveAll;
Wrapping Up
This project started out with a lot of research, but once the right solution was found it was pretty easy to implement. The required changes were minor, but the effect of getting this feature back in action for our customers will be a big win!
If you are ready to get this feature updated in Dovetail Agent, I’d love to help you. Leave a comment below.