Platform SDK: CDO for Windows 2000

AddRelatedBodyPart Method

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

[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 URL,
    BSTR Reference,
    CdoReferenceType ReferenceType,
   [BSTR UserName,]
   [BSTR Password,]
    IBodyPart** pVal
);
[IDL]
HRESULT AddRelatedBodyPart(
   [in] BSTR URL,
   [in] BSTR Reference,
   [in] CdoReferenceType ReferenceType,
   [in, optional] BSTR UserName,
   [in, optional] BSTR Password,
   [out,retval] IBodyPart** pVal
);

Parameters

URL
The full path and file name of the resource to be associated with the new body part.
Reference
The Content-ID or Content-Location header that a rendering client can use to reference the new body part.
ReferenceType
The method of referencing the new body part. This parameter determines which type of content header is placed in this Multipurpose Internet Mail Extensions (MIME) subpart. The value is one of the CdoReferenceType enumerated values.

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

UserName
An optional user name to use for authentication when retrieving the resource using Hypertext Transfer Protocol (HTTP). Can be used to set the credentials for both the basic and NTLM authentication mechanisms.
Password
An optional password to use for authentication when retrieving the resource using HTTP. Can be used to set the credentials for both the basic and NTLM authentication mechanisms.

Remarks

This method is intended to associate a Uniform Resource Locator (URL) within the content of a Multipurpose Internet Mail Extensions (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. Microsoft 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 Hypertext Tranfer Protocol (HTTP) from a server that requires client authentication. If the Web server supports only the basic authentication mechanism, these credentials must be supplied. If the Web server supports the NTLM authentication mechanism, by default. the current process security context is used to authenticate; however, you can specify alternate credentials for NTLM authentication with the UserName and Password parameters.

Example

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iMsg as New CDO.Message 

Dim strHTML as String
strHTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL 
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

iMsg.Send 

See Also

CdoReferenceType Enum