This documentation is archived and is not being maintained.

AddRelatedBodyPart Method

Exchange Server 2003

AddRelatedBodyPart Method

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The AddRelatedBodyPart method adds a BodyPart object that is referenced by content in the HTML body of the message.

Applies To

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In



        [Visual Basic]Function AddRelatedBodyPart
    ByVal URL As String,     ByVal Reference As String,     ByVal ReferenceType As CdoReferenceType,     ByVal [UserName As String],     ByVal [Password As String]
) As IBodyPart

        [C++]HRESULT AddRelatedBodyPart
    BSTR Reference,
    CdoReferenceType ReferenceType,
    BSTR UserName,
    BSTR Password,
    IBodyPart** pVal


The full path and file name of the resource to be associated with the new body part.
The Content-ID or Content-Location header that a rendering client can use to reference the new body part.

The method of referencing the new body part. This parameter will determine which type of Content header is placed in this Multipurpose Internet Mail Extensions (MIME) subpart. The value is one of the CdoReferenceType Enum values.

See RFC 2110 and RFC 2111 for further information about using Content-ID and Content-Location headers in messages formatted in MIME Encapsulation of Aggregate HTML Documents (MHTML).

An optional user name to use for authentication when retrieving the resource using HTTP. This name can be used to set the credentials for basic, NTLM, and Negotiate (Kerberos) authentication packages.
An optional password to use for authentication when retrieving the resource using HTTP. This password can be used to set the credentials for basic, NTLM, and Negotiate (Kerberos) authentication packages.
Returned reference to an IBodyPart Interface.

Return Value

Returns S_OK if successful, or an error value otherwise.


This method is intended to associate a URL within the content of a MIME body part to another body part in the MIME hierarchy. The AddRelatedBodyPart method is commonly used to attach graphics inline instead of referring to them using a URL.

The AddRelatedBodyPart method creates a body part by getting the contents specified by the URL parameter. It returns the IBodyPart object reference on the BodyPart object that is added to the collection of body parts of this message.

Calling the AddRelatedBodyPart method causes this message to become an MHTML-formatted message. Collaboration Data Objects (CDO) automatically sets the MimeFormatted property to TRUE and constructs the necessary multipart/related body part hierarchy. The ContentMediaType property of the new HTML body part is automatically set to text/html. The Content-ID or Content-Location header field of the related body part is set using the mechanism specified using the Reference and ReferenceType parameters, and its Content-Disposition header field is set to inline.

Normally, you populate the IMessage.HTMLBody property before calling the AddRelatedBodyPart method. The HTML can contain links to graphics and other resources. If the HTMLBody property is not set, or if its tag does not match the Content-Location header field of the new body part, the AddRelatedBodyPart method adds the body part without relating it to anything else.

Use the UserName and Password parameters when you are requesting Web pages using HTTP from a server that requires client authentication. If the Web server supports only the basic authentication mechanism, these credentials must be supplied. By default the current process security context is used to authenticate when using the NTLM or Negotiate (Kerberos) security packages; however, you can specify alternative credentials with the UserName and Password parameters.


        [Visual Basic]

Dim iMsg As New CDO.Message
' ... .MimeFormatted defaults to True on the new message ...
Dim strHTML As String ' string in which to build up HTML body
' ...
Set iMsg = New CDO.Message
strHTML = strHTML & "<HTML>"
strHTML = strHTML & "  <HEAD>"
strHTML = strHTML & "    <TITLE>Sample GIF</TITLE>"
strHTML = strHTML & "  </HEAD>"
strHTML = strHTML & "  <BODY><p>"
strHTML = strHTML & "   <IMG src=""XYZ.gif""></p><p>Inline graphics</p>"
strHTML = strHTML & "  </BODY>"
strHTML = strHTML & "</HTML>"
iMsg.HTMLBody = strHTML

iMsg.AddRelatedBodyPart "D:\wwwroot\XYZ.gif", "XYZ.gif", cdoRefTypeId


See Also

CdoReferenceType Enum