Evolution of CDO for NTS

CDO for NTS is the latest of a number of incarnations of ActiveX messaging components made available by Microsoft to web developers. The first of these was the OLE Messaging component which had a makeover after Microsoft's image police got hold of it and re-emerged as the Active Messaging component. This was simply a library (OLEMSG.DLL) whose fairly rudimentary object hierarchy was exposed by the type libraries MSDISP.TLB and MSDISP32.TLB. One of the problems with OLE Messaging was that in order to send even a simple mail message, the developer had to have a fairly clear understanding of MAPI (the Messaging API which formed part of Microsoft's open systems architecture model.)

The following portion of code illustrates the amount of code required to create a simple message using the OLE Messaging from Visual Basic.

Dim objSession As Object
Dim objMessage As Object
Dim objRecipient As Object

Set objSession = CreateObject("mapi.session")
objSession.Logon ProfileName:="My Profile"
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Bad News."
objMessage.Text = "I owe you £50."
Set objRecipient = objMessage.Recipients.Add
objRecipient.Name = "John de Robeck"
objRecipient.Type = mapiTo
objRecipient.Resolve
objMessage.Send showDialog:=False
MsgBox "Message sent successfully!"
objSession.Logoff

After the initial dimensioning of the variables, the first statement creates a Session object.

Set objSession = CreateObject("mapi.session")

The Logon method of this object is then invoked and the name of the user's profile is supplied as the named ProfileName argument.

objSession.Logon ProfileName:="My Profile"

The next step is to create a new Message object and append this to the Messages collection of the Outbox object for the current Session.

Set objMessage = objSession.Outbox.Messages.Add

The subject text and body text for this message are then set.

objMessage.Subject = "Bad News."
objMessage.Text = "I owe you £50."

The next stage is to build the recipient list. This is done by creating a Recipient object, specifying the name of the recipient and then stating that the recipient is a 'To' recipient (as opposed to a CC or BCC recipient).

Set objRecipient = objMessage.Recipients.Add
objRecipient.Name = "John de Robeck"
objRecipient.Type = mapiTo

The next statement causes the recipient's name to be resolved to the name of a user designated in the appropriate address book. If the name cannot be resolved directly, a dialog will be displayed to allow the user to select an appropriate name.

objRecipient.Resolve

After silently sending the message, a dialog is displayed to indicate that the message has been sent and the session is closed.

objMessage.Send showDialog:=False
MsgBox "Message sent successfully!"
objSession.Logoff

When we step through the code like this, it is easy enough to see how it all works. Having said that, it is not very intuitive to newcomers.

Active Messaging

With Microsoft Exchange Server version 5.0, Active Messaging 1.1 was unleashed into the developer community. In fact, Active Messaging 1.1 consisted of two components. The Active Messaging Component was used to log on to a mail server in similar fashion to the previous OLE Messaging component. Once a connection had been made, the other component - the HTML Rendering Component - allowed web developers to easily convert MAPI elements such as mailboxes and messages into HTML text which could be used in conjunction with Active Server Pages. The Exchange Web Client, which shipped with Exchange Server 5.0 and provided the capability to connect to an Exchange Server and access one's mailbox via the Internet, was probably the most obvious demonstration of the capabilities of the use of these components.

The next version of Active Messaging to be released accompanied the launch of Exchange Server version 5.5. Again, the Microsoft marketing people got into the act and Active Messaging was granted the ultimate seal of approval – a TLA (three letter acronym) – and it was renamed as Collaboration Data Objects or CDO 1.2.

Collaboration Data Objects 1.2

CDO 1.2 does actually represent a significant step forward from Active Messaging 1.1. Whereas Active Messaging was designed to allow developers to have programmatic access to simple messaging functionality, CDO 1.2 provides support for more advanced features such as calendaring, collaboration and workflow. CDO 1.2 can be used to design complex messaging applications on both the client and server sides and can be accessed from a variety of languages such as VBScript, Java, C, C++ and Visual Basic. CDO 1.2 has been designed for use with Exchange 5.5 and it doesn't have any user interface elements such as logon boxes or dialogs. However, as with its predecessor, CDO 1.2 contains a set of rendering objects which allow the automatic rendering of content to HTML for display in web browsers. We will look very briefly at CDO 1.2 later on in this chapter, but first we will look at the most recent incarnation of messaging libraries made available by Microsoft.

CDO for NTS

Collaboration Data Objects for NT Server (CDO for NTS) is a subset of CDO 1.2 and is designed for use by developers who want the ability to incorporate fast large-scale messaging into their applications without the need for advanced functionality such as calendaring, scheduling or workflow. It is shipped with Internet Information Server 4 and can be run against either the SMTP Server component of IIS4 or against Exchange Server 5.5 itself. The limited functionality of the SMTP Server in IIS4 is mirrored in the reduced complexity of CDO for NTS when compared to the full-blown CDO 1.2 implementation. CDO for NTS is basically an interface to allow developers to easily add simple mailing capabilities to their web sites.

The emphasis on ease of use at the expense of sophistication is best illustrated by the NewMail object in CDO for NTS. Using this new object, it is now possible to send a message in as few as three lines of code.

Set objMail = CreateObject("CDONTS.Newmail")
objMail.Send ("rob@here.com", "jdr@there.com", "Bad news", "I owe you £50")
Set objMail = Nothing

When deciding whether to use CDO 1.2 or CDO for NTS, you should bear in mind that CDO 1.2 is best at what Microsoft Exchange is good at. So if your application requires calendaring functionality, threaded conversations, complex messaging or workflow, you would be better off with CDO 1.2. However, if all you want is a lightweight component for sending out messages without the need for individual mailboxes, then CDO for NTS probably fits the bill.

Applications which use CDO for NTS can be run against Exchange Server 5.5 but, if this is to be done, then IIS 4.0 must also be installed on the Exchange server. The typical installation of IIS 4.0 is sufficient to install the relevant library (CDONTS.DLL). You should note that once IIS 4.0 has been installed on the Exchange server, you will need to run the IMS Wizard, which is part of Exchange Server 5.5. If you don't run this wizard, then applications using CDO for NTS will use the SMTP service provided by IIS 4.0 rather than running against the Exchange server.

© 1998 by Wrox Press. All rights reserved.