Microsoft KB Archive/169031

From BetaArchive Wiki

HOWTO: Embed a Document in a Message Using CDO (1.x)


The information in this article applies to:

  • Collaboration Data Objects (CDO), versions 1.0a, 1.1, 1.2, 1.21


Using CDO (1.x), it is possible to embed a file in a message so that the contents of the file are viewed when the message is opened--for example, embedding a bitmap into the message so that the actual bitmap appears when you open the message.


The code provided is a sample of performing this task in Microsoft Visual Basic.

Steps to Embed a File in a Message

  1. Create a MAPI Session object and call the Logon method:
  2. Create a Message and Attachment object:
  3. Set the Type property of the Attachment to indicate an OLE object:
  4. For Collaboration Data Objects (CDO) versions 1.0 and 1.1 only:

Set the Source property of the Attachment to the class of the OLE object:

  1. Use the ReadFromFile method of the Attachment to load the contents of the file for the OLE object and the Update method of the Message to save both the Attachment and the message:
  2. Send the Message:
  3. Call the Logoff method of the session:

Other Types of Message Attachments

Below are the four types of attachments that may be specified for a message and the corresponding Active Messaging 1.1 constants used when assigning the Type property of the attachment:

  • The contents of a file (you see an icon in the message representing the data in the file), ActMsgFileData
  • A link to a file (usually on a file server), ActMsgFileLink
  • An OLE object (example above), ActMsgOLE
  • An embedded message, ActMsgEmbeddedMessage

The return value or setting of the Source property depends on the value of the Type property, as described in the following table:

   Type property            Source property
   ----------------         ---------------------------------------------

   ActMsgFileData           Specifies the full path of the file that will
                            be attached when the ReadFromFile method is
                            called later. It is not necessary to set this
                            property if the source is specified in the call
                            to the Add method of the Attachments

   ActMsgFileLink           Specifies a full path name in a universal
                            naming convention (UNC) format, such as

   ActMsgOLE                Specifies the registered OLE class name of the
                            attachment, such as Word.Document or
                            PowerPoint.Show. The actual file contents would
                            be loaded with the ReadFromFile method.

   ActMsgEmbeddedMessage    Specifies the unique identifier of the message
                            to be embedded; returns the embedded Message


For additional information about Collaboration Data Objects (1.x) versus Active Messaging, please see the following article in the Microsoft Knowledge Base:

Q176916 INFO: Active Messaging and Collaboration Data Objects (1.x)

Microsoft Developer Network, Platform SDK, "Source Property (Attachment Object)"

Additional query words:

Keywords : kbcode kbActMsg kbCDO100 kbCDO110 kbCDO120 kbCDO121 kbMsg kbOLEMsg kbGrpDSMsg
Issue type : kbhowto
Technology : kbAudDeveloper kbCDOsearch kbExchangeSearch kbCDO100a kbCDO110 kbCDO120 kbCDO121

Last Reviewed: April 29, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.