Platform SDK: CDO for Windows 2000

Message CoClass

The Message Component Object Model (COM) class defines an object that represents a message.

CLSID
CD000001-8B95-11D1-82DB-00C04FB1625D
ProgID
CDO.Message
Type Library
Microsoft CDO for Windows 2000 Library
Inproc Server
CDOSYS.DLL
Threading Model
Both

Implemented Interfaces

IBodyPart

IDataSource

IMessage

Fields

The following fields can be used with instances of the Message COM class.

Name Description
urn:schemas:mailheader: namespace All fields defined within this namespace.
urn:schemas:httpmail: namespace All fields defined within this namespace.
http://schemas.microsoft.com/exchange/sensitivity field The Sensitivity header field for the message (an enumerated value in this namespace).
http://schemas.microsoft.com/cdo/smtpenvelope/ namespace Simple Mail Transfer Protocol (SMTP) transport event sinks only. Contained in the IMessage.EnvelopeFields collection.
http://schemas.microsoft.com/cdo/nntpenvelope/ namespace Network News Transfer Protocol (NNTP) transport event sinks only. Contained in the IMessage.EnvelopeFields collection.

Remarks

Instances of the Message COM class represent a complete message. The primary and default interface on a Message object is the IMessage interface. You use this interface to access the functionality of the object that is specific to messaging, including addressing and adding content to the message; and sending, posting, or responding to the message.

The IMessage interface provides a set of top-level methods and properties that are designed to make creating the most common message content a simple and intuitive process. Methods include CreateMHTMLBody, AddBodyPart, and AddAttachment. Properties include TextBody and HTMLBody.

For messages formatted in Multipurpose Internet Mail Extensions (MIME), the Message object acts as the root body part of the MIME body part hierarchy. This functionality is provided through the exposed IBodyPart interface on the object. The IMessage interface provides the BodyPart property that returns this interface on the object. You can use the BodyPart property, the GetInterface method, or standard mechanisms such as Set in Microsoft® Visual Basic®, and QueryInterface in C++ to navigate to this interface.

To facilitate the easy transfer of message data to and from other objects, the Message object provides an implementation of the IDataSource interface. Using methods and properties on this interface, you can access messages that are embedded in other messages, and you can also embed messages in other messages. The IMessage interface provides the DataSource property to aid in navigating to the IDataSource interface on the object.

Example

[Visual Basic]
Dim iMsg as new CDO.Message
Dim iBp as CDO.IBodyPart
Dim iConf as New CDO.Configuration
Dim Flds as ADODB.Fields

Set Flds = iConf.Fields
' Use string constants for field names.
Flds(cdoSendUsingMethod)           = cdoSendUsingPickup
Flds(cdoSMTPServerPickupDirectory) = "c:\\Inetpub\\mailroot\\Pickup"
Flds(cdoURLProxyServer)            = "server"
Flds(cdoURLProxyBypass)            = "<local>"
Flds(cdoURLGetLatestVersion)       = True
Flds.Update

Set iMsg.Configuration = iConf

Set Flds = Msg.Fields
With Flds
  .Item("urn:schemas:mailheader:to")     = "someone@microsoft.com"
  .Item("urn:schemas:mailheader:from")   = "me@msn.com,another@msn.com"
  .Item("urn:schemas:mailheader:sender") = "me@microsoft.com"
  .Item("urn:schemas:mailheader:subject")= "Check this stuff out."
  .Update
End With

With iMsg
  .AddAttachment("c:\somefile.ext")
  .AddAttachment("c:\anotherfile.ext2")
  .CreateMHTMLBody "http://myserver/mypage.html", cdoSuppressNone
  .Send
End With
[C++,IDL]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include <cdosysstr.h>  // string constants in this file
#include <iostream.h>

main(){
  CoInitialize(NULL);  // single-threaded apartment
  IMessage* pMsg = NULL;
  /* 
  ** Create an instance of the Message COM class.
  */
  HRESULT hr = CoCreateInstance(__uuidof(Message),
                                NULL,
                                CLSCTX_INPROC_SERVER,
                                __uuidof(IMessage),
                                reinterpret_cast<void**>(&pMsg));
  assert(SUCCEEDED(hr));

  Fields* pFlds = NULL;
  pMsg->get_Fields(&pFlds);

  Field* pFld   = NULL;
  pFlds->get_Item(_variant_t("urn:schemas:mailheader:to"),&pFld);
  pFld->put_Value(_variant_t("someone@microsoft.com"));
  pFld->Release();

  pFlds->get_Item(_variant_t("urn:schemas:mailheader:from"),&pFld);
  pFld->put_Value(_variant_t("me@microsoft.com,another@micfosoft.com"));
  pFld->Release();

  pFlds->get_Item(_variant_t("urn:schemas:mailheader:sender"),&pFld);
  pFld->put_Value(_variant_t("me@microsoft.com"));
  pFld->Release();

  pFlds->get_Item(_variant_t("urn:schemas:mailheader:subject"),&pFld);
  pFld->put_Value(_variant_t("Check this stuff out"));
  pFld->Release();

  pFlds->Update();
  pFlds->Release();

  IBodyPart* pBP = NULL;
  pMsg->AddAttachment(L"c:\somefile.ext",&pBP);
  pBP->Release();
  pBP = NULL;
  
  pMsg->AddAttachment(L"c:\anotherfile.ext2",&pBP);
  pBP->Release();
  pBP = NULL;
  
  pMsg->CreateMHTMLBody(L"http://myserver/mypage.html");

  pMsg->Send();  
  pMsg->Release();
  CoUninitialize();
  return 0;
}

See Also

IMessage Interface

IBodyPart Interface

IDataSource Interface