Embedding a Message into Another

Embedding a Message into Another

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 one 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 Multipurpose Internet Mail Extensions (MIME) hierarchy as a body part with Content-Type message/rfc822.

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

  1. Obtain an IMessage object reference on the Message object containing the message that you want to embed.
  2. Obtain the IDataSource interface on that object.
  3. Obtain the IBodyPart object reference on the BodyPart object located within the body part hierarchy of the Message object in which you want to embed the message.
  4. Call the IDataSource.SaveToObject method 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 embedding the message again. Because the Message and BodyPart objects are currently bound, you need only call the IDataSource.Save method.
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Sub EmbedMessage(iMsg As CDO.Message, iBp As IBodyPart)
    Dim iDsrc As IDataSource
    Set iDsrc = iMsg
    iDsrc.SaveToObject iBp, "IBodyPart"
End Sub

#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.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;
      }
}
Sub EmbedMessage(iMsg, iBp)
    Dim iDsrc
    Set iDsrc = iMsg.DataSource
    iDsrc.SaveToObject iBp, "IBodyPart"
End Sub

See Also

Concepts

SaveToObject Method
OpenObject Method
IDataSource Interface