Platform SDK: Exchange 2000 Server

Embedding a Message

[This is preliminary documentation and subject to change.]

You can use the IDataSource.SaveToObject method to "copy" an entire Message object into another Message object. This is most useful when you want to embed the message into another as a body part. If you embed Message A into Message B, Message B would then contain message A in its entirety within its MIME hierarchy as a body part with Content-Type "message/rfc822."

To embed a message into another, perform the following steps:

  1. Obtain an IMessage object reference on the Message object containing the message you wish to embed.
  2. Obtain the IDataSource interface on that object.
  3. Obtain the IBodyPart object reference on the BodyPart object within the body part hierarchy of the Message object in which you want to embed the message.
  4. Call IDataSource.SaveToObject on the first Message object, passing the IBodyPart object reference as the first parameter, and the string "IBodyPart" as the second. This step embeds the message and creates a binding between the Message and BodyPart objects.
  5. If you make changes to the message, you can save them by re-embedding the message. Because the Message and BodyPart objects are currently bound, you need only call IDataSource.Save.
[Visual Basic]
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Server Library
' ..
Sub EmbedMessage(iMsg As CDO.Message, iBp As IBodyPart)
    Dim iDsrc As IDataSource
    Set iDsrc = iMsg
    iDsrc.SaveToObject iBp, "IBodyPart"
End Sub
[C++,IDL]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\exchsrvr\cdoex.dll" no_namespace
// ...
void EmbedMessage( IMessagePtr iMsg, IBodyPartPtr iBp)
{
      IDataSourcePtr iDsrc;
      iDsrc = iMsg;

      try 
      {      
            iDsrc->SaveToObject(iBp,_bstr_t("IBodyPart"));
      }
      catch(_com_error error)
      {
            throw error;
      }
}
[VBScript]
Sub EmbedMessage(iMsg As CDO.Message, iBp As IBodyPart)
    Dim iDsrc
    Set iDsrc = iMsg.DataSource
    iDsrc.SaveToObject iBp, "IBodyPart"
End Sub