Platform SDK: Exchange 2000 Server

Creating MHTML-Formatted Messages

[This is preliminary documentation and subject to change.]

MHTML formatting provides a simple way to send portions or an entire Web page as a message. The message includes all of the HTML formatting, graphics, and other elements contained in the original page. You can also choose to exclude one or more types of elements from the message.

The IMessage.CreateMHTMLBody method accepts a URL parameter and a flags parameter. The URL specifies the Web page being sent, and the optional flags specify the types of elements to exclude from the message. CDO makes the file specified by the URL the IMessage.HTMLBody of the message, and each graphic or other element referenced in that file becomes a MIME body part. By default, CDO automatically generates the text body that contains a plain text version of the HTMLBody content.

CDO must be able to access the specified source URL to create the message. If CDO needs to use a proxy server to reach a URL outside a firewall, set this location for the http://schemas.microsoft.com/cdo/configuration/urlproxyserver field in the Message object's associated Configuration object.

The following example shows how to create a message from a Web page.

[Visual Basic]
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Server Library
' ..
Dim iMsg  as New CDO.Message
Dim iConf as New CDO.Configuration
Dim Flds  as ADODB.Fields

Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/urlproxyserver") = "proxyname:80"
Flds("http://schemas.microsoft.com/cdo/configuration/urlproxybypass") = "<local>"
Flds("http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion") = True
Flds.Update

Set iMsg.Configuration = iConf

iMsg.CreateMHTMLBody "http://example.microsoft.com", _
                     cdoSuppressAll, _
                     "domain\username", _
                     "password"

' ...
[C++,IDL]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\exchsrvr\cdoex.dll" no_namespace
// ...
IMessagePtr       iMsg(__uuidof(Message));
IConfigurationPtr iConf(__uuidof(Configuration));
FieldsPtr         Flds;

Flds = iConf->Fields;
Flds->Item["http://schemas.microsoft.com/cdo/configuration/urlproxyserver"]->Value
  = _variant_t("myproxyserver:80");
Flds->Item["http://schemas.microsoft.com/cdo/configuration/urlproxybypass"]->Value
  = _variant_t("<local>");
Flds->Item["http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion"]->Value
  = _variant_t(VARIANT_TRUE);
Flds->Update();
iMsg->Configuration = iConf;
try
{
  iMsg->CreateMHTMLBody(
           "http://example.microsoft.com", 
           cdoSuppressAll,
           "domain\\username",
           "password");
}
catch(_com_error err)
{
  // handle exception
}
[VBScript]
Dim iMsg
Dim iConf
Dim Flds

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/urlproxyserver") = "proxyname:80"
Flds("http://schemas.microsoft.com/cdo/configuration/urlproxybypass") = "<local>"
Flds("http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion") = True
Flds.Update

Set iMsg.Configuration = iConf

iMsg.CreateMHTMLBody "http://example.microsoft.com", _
                      cdoSuppressAll, _
                      "domain\username", _
                      "password"

Note   To suppress multiple elements, add the values of the flag constants. For example, to suppress images and style sheets, specify the flags parameter as (cdoSuppressImages + cdoSuppressStyleSheets).

See Also

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

IMessage.CreateMHTMLBody Method

cdoMHTMLFlags Enum