Partager via


Embedding a Message

Topic Last Modified: 2006-06-12

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 then contains all of message A in its Multipurpose Internet Mail Extensions (MIME) hierarchy as a body part with Content-Type "message/rfc822."

To embed one message in another

  1. Obtain an IMessage object reference on the Message object containing the message you want 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 Save Method.

Example

Visual Basic

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Server Library

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
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:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace

// Note: It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
void EmbedMessage( IMessagePtr& iMsg, IBodyPartPtr& iBp)
{
      IDataSourcePtr iDsrc;
      iDsrc = iMsg;

      try
      {
            iDsrc->SaveToObject(iBp,_bstr_t("IBodyPart"));
      }
      catch(_com_error error)
      {
            throw error;
      }
}

VBScript

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.

Sub EmbedMessage(iMsg As CDO.Message, iBp As IBodyPart)
    Dim iDsrc
    Set iDsrc = iMsg.DataSource
    iDsrc.SaveToObject iBp, "IBodyPart"
End Sub