The CreateMHTMLBody method converts the contents of an entire Web page into a MIME Encapsulation of Aggregate HTML Documents (MHTML) formatted message body.
Sub CreateMHTMLBody( ByVal URL as String, [ByVal Flags as CdoMHTMLFlags = 0], [ByVal UserName as String], [ByVal Password as String] ) HRESULT CreateMHTMLBody( BSTR URL, CdoMHTMLFlagsFlags=cdoSuppressNone, BSTR UserName, BSTR Password );
The full path and file name of the Web page.
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.
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.
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.
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:
If defined, these cookies are sent with the request for the resource.
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.
If set, the Transmission Control Protocol/Internet Protocol (TCP/IP) connection to the Web server is obtained using the specified proxy server.
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.
Important Storing user names and passwords inside source code can lead to security vulnerabilities in your software. Do not store user names and passwords in your production code.
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.
' 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 ' IMPORTANT: Storing user names and passwords inside source code ' can lead to security vulnerabilities in your software. Do not ' store user names and passwords in your production code. .CreateMHTMLBody "http://InternalNTLMAuthRequiredServer", _ "domain\username", _ "password" .To = "email@example.com" .From = "firstname.lastname@example.org" .Subject = "an example mhtml formatted message with attachment" .AddAttachment "http://server.example.com" .Send End With