Platform SDK: CDO for Windows 2000

CreateMHTMLBody Method

The CreateMHTMLBody method converts the contents of an entire Web page into a MIME Encapsulation of Aggregate HTML Documents (MHTML) formatted message body.

[Visual Basic]
Sub CreateMHTMLBody(
   ByVal URL as String,
   [ByVal Flags as CdoMHTMLFlags = 0],
   [ByVal UserName as String],
   [ByVal Password as String]
)
[C++]
HRESULT CreateMHTMLBody(
   BSTR URL,
   CdoMHTMLFlags Flags=cdoSuppressNone,
   BSTR UserName,
   BSTR Password
);

[IDL]
HRESULT CreateMHTMLBody(
   [in] BSTR URL,
   [in, defaultvalue(0), optional] CdoMHTMLFlags Flags,
   [in, optional] BSTR UserName,
   [in, optional] BSTR Password
);

Parameters

URL
The full path and file name of the Web page.
Flags
A bit mask of flags controlling inclusion of items from the Web page as related body parts. The flags are defined in the CdoMHTMLFlags enumeration. The default value of Flags is CdoSuppressNone.
UserName
An optional user name to use for authentication when retrieving the resource using Hypertext Tranfer 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

The CreateMHTMLBody method scans the Web page for links and attachments and creates appropriate body parts on this message.

The CreateMHTMLBody method adds new body parts to the message but does not delete any existing ones; however, it replaces any previous contents of the HTMLBody property. In so doing, it rewrites Uniform Resource Locators (URLs) as Content-ID URLs. For example,

<IMG SRC="http://abc/xyz.gif"> might be rewritten as <IMG SRC="cid:000301bd9ad5$09a6b9f8$_CDOSYS2.0">. 

The Content-ID URL uniquely references the individual body part that contains the image. For more information on Content-ID, see Multipurpose Internet Mail Extensions (MIME) Headers.

It is recommended that you create a new message before calling the CreateMHTMLBody method. If you decide to reuse a message, use the IBodyParts.DeleteAll method to remove all BodyPart objects from the message.

The CreateMHTMLBody method uses the following fields in the http://schemas.microsoft.com/cdo/configuration/ namespace. These fields are defined in the Configuration object referenced by the IMessage.Configuration property:

Field Description
httpcookies
If defined, these cookies are sent with the request for the resource.
urlgetlatestversion
If set to True (VARIANT_TRUE), local cached copies of the resource are bypassed and the object requests the resource directly from the web server.
urlproxyserver
If set, the Transmission Control Protocol/Internet Protocol (TCP/IP) connection to the Web server is obtained using the specified proxy server.
urlproxybypass
If set to "<local>", the proxy server is bypassed when connecting to local Internet Protocol (IP) addresses.

After you call the CreateMHTMLBody method, you can add or modify body parts, set the TextBody property, and modify the HTMLBody property.

The CreateMHTMLBody method matches (case-insensitive) patterns on the Content-Type header field when loading from a Uniform Resource Locator (URL). If the resource specified by the URL parameter is not found, an error is returned.

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. 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.

The CreateMHTMLBody method is commonly used to send the contents of a Web page to a messaging user. This can be useful, for example, for news or stock report services.

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 iConf as New CDO.Configuration
Dim Flds  as ADODB.Fields
Set Flds = iConf.Fields
Flds(cdoURLProxyServer)      = "myserver:80"
Flds(cdoURLProxyBypass)      = "<local>"
Flds(cdoURLGetLatestVersion) = True
Flds.Update

With iMsg
   Set .Configuration = iConf
   .CreateMHTMLBody "http://InternalNTLMAuthRequiredServer", _
                    "domain\username", _
                    "password" 
   .To      = "MyCustomer@microsoft.com" 
   .From    = "me@microsoft.com"
   .Subject = "an example mhtml formatted message with attachment"
   .AddAttachment "http://www.microsoft.com"
   .Send 
End With

See Also

http://schemas.microsoft.com/cdo/configuration/httpcookies Field

http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion Field

http://schemas.microsoft.com/cdo/configuration/urlproxyserver Field

http://schemas.microsoft.com/cdo/configuration/urlproxybypass Field

CdoMHTMLFlags Enum