谁研究过IE的*.mht文件格式?我如何自己创建这种文件?为什么我把存好的*.mht文件换了后缀IE就无法识别?如何利用IHTMLXXX接口动态显示mht? 谁研究过IE的*.mht文件格式?我如何自己创建这种文件?为什么我把存好的*.mht文件换了后缀IE就无法识别?如何利用IHTMLXXX接口动态显示mht? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我现在需要将整个网页(包括各种media文件)一起存到数据库中之后,需要将该页从数据库中读出来用IE浏览。MHT是最好的解决办法,不用建多个表……可是,存储和浏览都成了问题,这里还需要指出的是,我没有使用IE控件,还没有办法将网页保存成MHT格式的文件! 你看一下下面这篇文章是否有用? VCKBASE Online Help Journal No.10 关于几个HTML文档接口的使用探讨 赵湘宁 问题: 在使用Active Accessibility SDK的过程中,我从某个窗口的句柄来获得IHTMLDocument2指针。有没有什么方法可以从IHTMLDocument2指针来获得IWebBrowser2指针?我用QueryInterface在两个接口(IHTMLDocument2 和 IWebBrowser2)上试过,但没有成功。我也用网景(Netscape)的 HTMLWindow2 指针试过从get_navigator获取IOmNavigator *。也以失败告终。请高手指点。 解答: 这个问题通常是COM编程中存在的共性问题。你有了窗口,文档,或者浏览器,你明明知道可以通过这些已知数据来得到其它的信息,但往往在实际环境中一运行,QueryInterface总是给你送回一个肥大的NULL。这个问题的答案实际上隐藏在神秘的IServiceProvider接口中,顾名思义,IServiceProvider的作用就是提供服务。IServiceProvider是个非常棒的接口:它只有一个方法——QueryService。如果你会用ATL智能指针,就像下面这样。首先必须获得IServiceProvider接口, CComQIPtr<IServiceProvider> isp = pIHTMLDocument2; 这行代码实际上就是对文档执行了一次 QueryInterface,以询问IServiceProvider接口。一旦具备了isp,你便可以象下面这样获得浏览器。 CComQIPtr<IWebBrowser2> iwb2;isp->QueryService(IID_IWebBrowserApp,IID_IWebBrowser2, (void**)&iwb2); 如果你还是不明白上面所讲东西,没有关系,很正常。COM编程的一个根本规则是:QueryInterface必须总是要返回所查询对象的接口。但是文档不实现 IWebBrowser2 接口,它只知道如何获得正在工作的对象。文档,浏览器和窗口都是独立的对象。通常IServiceProvider被用于多个单独且相关的COM对象群来实现某种类型的服务。QueryInterface询问某个对象:“你实现这个接口吗?”,而QueryService告诉某个服务提供者,“不管什么对象实现这个接口都要告诉我。” 使用QueryService返回的接口指针与所查询的对象可能相同,也可能不相同。如图一所示。所有对象都实现它们自己不同的接口并在内部存储指向另一个对象的指针。你必须用IServiceProvider接口来获得特定接口的对象,不论它是哪一个对象实现的。IServiceProvider::QueryService要追随这些内部指针来获取实现你所想要的接口对象。 图一 多个对象,一个IServiceProvider 从本质上讲,IServiceProvider用于导航DHTML对象层次。假设你正在写一个ActiveX控件来导航这个对象模型。你如何做呢?首先要像下面这样查询IOleClientSite来取得IServiceProvider: CComQIPtr<IServiceProvider> isp = pSite; 然后,一旦你具备了IServiceProvider,则可以用QueryService来从中查询应用对象。 CComQIPtr<IWebBrowserApp> iwba;isp->QueryService(IID_IWebBrowserApp, IID_IWebBrowserApp, (void **)&iwba); 接下来你就可以导航这个对象层次了(应用对象在最顶层)。如果你想要得到Web浏览器,那么与前面类似。 CComQIPtr<IWebBrowser2> iwb2;isp->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void **)&iwb2)); 在所有这些例子中,SID_SWebBrowserApp都是服务标示,但你也能常常见到将IID_IWebBrowserApp作为服务ID的代码。两种用法都可以行得通,因为<shlguid.h>文件中有个宏定义: #defines SID_SWebBrowserApp IID_IWebBrowserApp 但从编程的角度上讲,SID_SWebBrowserApp在技术上更正确,并且对阅读代码的人来说也更清晰。 此外,如果你有足够的勇气去实现像DHTML对象模型这类庞大的对象系统的话,你也要用到IServiceProvider接口...... 关于这个问题的解答我也只能浅尝辄止地说明到这个地步,再往深处走,我也蒙嚓嚓。更深层次的探讨请各位参见MSDN库。 由于个人水平所限,对解答中存在的错误与不详之处,请各位弟兄海涵。 --------------------------------------------------------------------------------©1997-2000 VCKBASE.COM All Rights Reserved. save in .eml formatCreating and Sending a MessageThe following example shows how to create a complete message that contains Hypertext Markup Language (HTML) and plain text versions and several attachments, and send it over the network. [Visual Basic] Dim iMsg as New CDO.MessageDim iConf as New CDO.ConfigurationDim Flds as ADODB.FieldsSet Flds = iConf.FieldsWith Flds .Item(cdoSendUsingMethod) = cdoSendUsingPort .Item(cdoSMTPServerName) = "[email protected]" .Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout .Item(cdoSMTPAuthenticate) = cdoBasic .Item(cdoSendUserName) = "username" .Item(cdoSendPassword) = "password" .Item(cdoURLProxyServer) = "server:80" .Item(cdoURLProxyBypass) = "<local>" .Item(cdoURLGetLatestVersion) = True .UpdateEnd WithWith iMsg Set .Configuration = iConf .To = """User A"" <[email protected]>" .From = """User B"" <[email protected]>" .Subject = "Hows it going? I've attached my web page" .CreateMHTMLBody "http://mypage" .AddAttachment "C:\files\mybook.doc" .SendEnd With[C++,IDL] #import "d:\program files\common files\system\ado\msado15.dll" no_namespace#import <cdosys.dll> no_namespace#include <iostream.h>void main(){ CoInitialize(NULL); { IMessagePtr iMsg(__uuidof(Message)); IBodyPartPtr iBp; IBodyPartsPtr iBps; _StreamPtr Stm; _bstr_t filepath; IConfigurationPtr iConf(__uuidof(Configuration)); FieldsPtr Flds; Flds = iConf->Fields; Flds->Item[cdoSendUsingMethod]->Value = _variant_t(cdoSendUsingPort); Flds->Item[cdoSMTPServerName]->Value = _variant_t("[email protected]"); Flds->Item[cdoSMTPConnectionTimeout]->Value = _variant_t((long)10); Flds->Item[cdoSMTPAuthenticate]->Value = _variant_t(cdoBasic); Flds->Item[cdoSendUserName]->Value = _variant_t("username"); Flds->Item[cdoSendPassword]->Value = _variant_t("password"); Flds->Item[cdoURLProxyServer]->Value = _variant_t("server:80"); Flds->Item[cdoURLProxyBypass]->Value = _variant_t("<local>"); Flds->Item[cdoURLGetLatestVersion]->Value = _variant_t(VARIANT_TRUE); Flds->Update(); iMsg->To = "\"SomeOne\" <[email protected]>"; iMsg->From = "\"Another\" <[email protected]>"; iMsg->Subject = "Here is a subject for the message."; /* ** attach an html file to message ** your local path goes in the "path" ** variable below */ try { filepath = _bstr_t(path) + _bstr_t("\\htmlfile.html"); iMsg->AddAttachment(filepath,"",""); } catch (_com_error e) { //... } /* ** Attach Word 2000 file to message */ try { filepath = _bstr_t(path) + _bstr_t("\\wordfile.doc"); iMsg->AddAttachment(filepath,"",""); } catch (_com_error e) { //... } /* ** Create MTHML body. */ try { iMsg->CreateMHTMLBody( "http://mypage", cdoSuppressAll, "", ""); } catch (_com_error e) { //... } iMsg->Send(); // save message Stm = iMsg->GetStream(); Stm->SaveToFile(_bstr_t("message.eml"),adSaveCreateOverWrite); } CoUninitialize();}[VBScript] Dim iMsgSet iMsg = CreateObject("CDO.Message")Dim iConf Set iConf = CreateObject("CDO.Configuration")Dim FldsSet Flds = iConf.FieldsWith Flds ' assume constants are defined within script file .Item(cdoSendUsingMethod) = 2 ' cdoSendUsingPort .Item(cdoSMTPServerName) = "[email protected]" .Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout .Item(cdoSMTPAuthenticate) = cdoBasic .Item(cdoSendUserName) = "username" .Item(cdoSendPassword) = "password" .Item(cdoURLProxyServer) = "server:80" .Item(cdoURLProxyBypass) = "<local>" .Item(cdoURLGetLatestVersion) = True .UpdateEnd WithWith iMsg Set .Configuration = iConf .To = """User A"" <[email protected]>" .From = """User B"" <[email protected]>" .Subject = "Hows it going? I've attached my web page" .CreateMHTMLBody "http://mypage" .AddAttachment "C:\files\mybook.doc" .SendEnd With save in .eml formatCreating and Sending a MessageThe following example shows how to create a complete message that contains Hypertext Markup Language (HTML) and plain text versions and several attachments, and send it over the network. [Visual Basic] Dim iMsg as New CDO.MessageDim iConf as New CDO.ConfigurationDim Flds as ADODB.FieldsSet Flds = iConf.FieldsWith Flds .Item(cdoSendUsingMethod) = cdoSendUsingPort .Item(cdoSMTPServerName) = "[email protected]" .Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout .Item(cdoSMTPAuthenticate) = cdoBasic .Item(cdoSendUserName) = "username" .Item(cdoSendPassword) = "password" .Item(cdoURLProxyServer) = "server:80" .Item(cdoURLProxyBypass) = "<local>" .Item(cdoURLGetLatestVersion) = True .UpdateEnd WithWith iMsg Set .Configuration = iConf .To = """User A"" <[email protected]>" .From = """User B"" <[email protected]>" .Subject = "Hows it going? I've attached my web page" .CreateMHTMLBody "http://mypage" .AddAttachment "C:\files\mybook.doc" .SendEnd With[C++,IDL] #import "d:\program files\common files\system\ado\msado15.dll" no_namespace#import <cdosys.dll> no_namespace#include <iostream.h>void main(){ CoInitialize(NULL); { IMessagePtr iMsg(__uuidof(Message)); IBodyPartPtr iBp; IBodyPartsPtr iBps; _StreamPtr Stm; _bstr_t filepath; IConfigurationPtr iConf(__uuidof(Configuration)); FieldsPtr Flds; Flds = iConf->Fields; Flds->Item[cdoSendUsingMethod]->Value = _variant_t(cdoSendUsingPort); Flds->Item[cdoSMTPServerName]->Value = _variant_t("[email protected]"); Flds->Item[cdoSMTPConnectionTimeout]->Value = _variant_t((long)10); Flds->Item[cdoSMTPAuthenticate]->Value = _variant_t(cdoBasic); Flds->Item[cdoSendUserName]->Value = _variant_t("username"); Flds->Item[cdoSendPassword]->Value = _variant_t("password"); Flds->Item[cdoURLProxyServer]->Value = _variant_t("server:80"); Flds->Item[cdoURLProxyBypass]->Value = _variant_t("<local>"); Flds->Item[cdoURLGetLatestVersion]->Value = _variant_t(VARIANT_TRUE); Flds->Update(); iMsg->To = "\"SomeOne\" <[email protected]>"; iMsg->From = "\"Another\" <[email protected]>"; iMsg->Subject = "Here is a subject for the message."; /* ** attach an html file to message ** your local path goes in the "path" ** variable below */ try { filepath = _bstr_t(path) + _bstr_t("\\htmlfile.html"); iMsg->AddAttachment(filepath,"",""); } catch (_com_error e) { //... } /* ** Attach Word 2000 file to message */ try { filepath = _bstr_t(path) + _bstr_t("\\wordfile.doc"); iMsg->AddAttachment(filepath,"",""); } catch (_com_error e) { //... } /* ** Create MTHML body. */ try { iMsg->CreateMHTMLBody( "http://mypage", cdoSuppressAll, "", ""); } catch (_com_error e) { //... } iMsg->Send(); // save message Stm = iMsg->GetStream(); Stm->SaveToFile(_bstr_t("message.eml"),adSaveCreateOverWrite); } CoUninitialize();}[VBScript] Dim iMsgSet iMsg = CreateObject("CDO.Message")Dim iConf Set iConf = CreateObject("CDO.Configuration")Dim FldsSet Flds = iConf.FieldsWith Flds ' assume constants are defined within script file .Item(cdoSendUsingMethod) = 2 ' cdoSendUsingPort .Item(cdoSMTPServerName) = "[email protected]" .Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout .Item(cdoSMTPAuthenticate) = cdoBasic .Item(cdoSendUserName) = "username" .Item(cdoSendPassword) = "password" .Item(cdoURLProxyServer) = "server:80" .Item(cdoURLProxyBypass) = "<local>" .Item(cdoURLGetLatestVersion) = True .UpdateEnd WithWith iMsg Set .Configuration = iConf .To = """User A"" <[email protected]>" .From = """User B"" <[email protected]>" .Subject = "Hows it going? I've attached my web page" .CreateMHTMLBody "http://mypage" .AddAttachment "C:\files\mybook.doc" .SendEnd With VC6.0调试导致死机 工程为什么有的类的方法我看不到它的实现?只看到它的声明?怎样看它的实现代码? 在软件开发过程中,文档怎样编写和整理 C/C++区没有人回答,只好到这边来看看。。。。。。 ClistView问题 做bho监视IE的时候,如何得到弹出窗口的网页内容? CSDN有没有象大富翁一样的离线数据库或CHM文档啊?有给个网址我下下 ADO编程wt 求助 为何我获取的IP都是一样的? 编辑框的大小随着输入文字的变化而改变大小 关于USB的HID通信 关于Socket通信的问题
关于几个HTML文档接口的使用探讨
赵湘宁
问题:
在使用Active Accessibility SDK的过程中,我从某个窗口的句柄来获得IHTMLDocument2指针。有没有什么方法可以从IHTMLDocument2指针来获得IWebBrowser2指针?我用QueryInterface在两个接口(IHTMLDocument2 和 IWebBrowser2)上试过,但没有成功。我也用网景(Netscape)的 HTMLWindow2 指针试过从get_navigator获取IOmNavigator *。也以失败告终。请高手指点。
解答:
这个问题通常是COM编程中存在的共性问题。你有了窗口,文档,或者浏览器,你明明知道可以通过这些已知数据来得到其它的信息,但往往在实际环境中一运行,QueryInterface总是给你送回一个肥大的NULL。这个问题的答案实际上隐藏在神秘的IServiceProvider接口中,顾名思义,IServiceProvider的作用就是提供服务。IServiceProvider是个非常棒的接口:它只有一个方法——QueryService。如果你会用ATL智能指针,就像下面这样。首先必须获得IServiceProvider接口,
CComQIPtr<IServiceProvider> isp = pIHTMLDocument2;
这行代码实际上就是对文档执行了一次 QueryInterface,以询问IServiceProvider接口。一旦具备了isp,你便可以象下面这样获得浏览器。
CComQIPtr<IWebBrowser2> iwb2;
isp->QueryService(IID_IWebBrowserApp,IID_IWebBrowser2, (void**)&iwb2);
如果你还是不明白上面所讲东西,没有关系,很正常。COM编程的一个根本规则是:QueryInterface必须总是要返回所查询对象的接口。但是文档不实现 IWebBrowser2 接口,它只知道如何获得正在工作的对象。文档,浏览器和窗口都是独立的对象。通常IServiceProvider被用于多个单独且相关的COM对象群来实现某种类型的服务。QueryInterface询问某个对象:“你实现这个接口吗?”,而QueryService告诉某个服务提供者,“不管什么对象实现这个接口都要告诉我。” 使用QueryService返回的接口指针与所查询的对象可能相同,也可能不相同。如图一所示。所有对象都实现它们自己不同的接口并在内部存储指向另一个对象的指针。你必须用IServiceProvider接口来获得特定接口的对象,不论它是哪一个对象实现的。IServiceProvider::QueryService要追随这些内部指针来获取实现你所想要的接口对象。
图一 多个对象,一个IServiceProvider
从本质上讲,IServiceProvider用于导航DHTML对象层次。假设你正在写一个ActiveX控件来导航这个对象模型。你如何做呢?首先要像下面这样查询IOleClientSite来取得IServiceProvider:
CComQIPtr<IServiceProvider> isp = pSite;
然后,一旦你具备了IServiceProvider,则可以用QueryService来从中查询应用对象。
CComQIPtr<IWebBrowserApp> iwba;
isp->QueryService(IID_IWebBrowserApp, IID_IWebBrowserApp, (void **)&iwba);
接下来你就可以导航这个对象层次了(应用对象在最顶层)。如果你想要得到Web浏览器,那么与前面类似。
CComQIPtr<IWebBrowser2> iwb2;
isp->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void **)&iwb2));
在所有这些例子中,SID_SWebBrowserApp都是服务标示,但你也能常常见到将IID_IWebBrowserApp作为服务ID的代码。两种用法都可以行得通,因为<shlguid.h>文件中有个宏定义:
#defines SID_SWebBrowserApp IID_IWebBrowserApp
但从编程的角度上讲,SID_SWebBrowserApp在技术上更正确,并且对阅读代码的人来说也更清晰。
此外,如果你有足够的勇气去实现像DHTML对象模型这类庞大的对象系统的话,你也要用到IServiceProvider接口......
关于这个问题的解答我也只能浅尝辄止地说明到这个地步,再往深处走,我也蒙嚓嚓。更深层次的探讨请各位参见MSDN库。
由于个人水平所限,对解答中存在的错误与不详之处,请各位弟兄海涵。
--------------------------------------------------------------------------------©1997-2000 VCKBASE.COM All Rights Reserved.
Creating and Sending a Message
The following example shows how to create a complete message that contains Hypertext Markup Language (HTML) and plain text versions and several attachments, and send it over the network. [Visual Basic]
Dim iMsg as New CDO.Message
Dim iConf as New CDO.ConfigurationDim Flds as ADODB.Fields
Set Flds = iConf.FieldsWith Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServerName) = "[email protected]"
.Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Item(cdoURLProxyServer) = "server:80"
.Item(cdoURLProxyBypass) = "<local>"
.Item(cdoURLGetLatestVersion) = True
.Update
End WithWith iMsg
Set .Configuration = iConf
.To = """User A"" <[email protected]>"
.From = """User B"" <[email protected]>"
.Subject = "Hows it going? I've attached my web page"
.CreateMHTMLBody "http://mypage"
.AddAttachment "C:\files\mybook.doc"
.Send
End With
[C++,IDL]
#import "d:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
#include <iostream.h>void main()
{
CoInitialize(NULL);
{
IMessagePtr iMsg(__uuidof(Message));
IBodyPartPtr iBp;
IBodyPartsPtr iBps;
_StreamPtr Stm;
_bstr_t filepath; IConfigurationPtr iConf(__uuidof(Configuration));
FieldsPtr Flds;
Flds = iConf->Fields;
Flds->Item[cdoSendUsingMethod]->Value =
_variant_t(cdoSendUsingPort);
Flds->Item[cdoSMTPServerName]->Value =
_variant_t("[email protected]");
Flds->Item[cdoSMTPConnectionTimeout]->Value = _variant_t((long)10);
Flds->Item[cdoSMTPAuthenticate]->Value = _variant_t(cdoBasic);
Flds->Item[cdoSendUserName]->Value = _variant_t("username");
Flds->Item[cdoSendPassword]->Value = _variant_t("password");
Flds->Item[cdoURLProxyServer]->Value = _variant_t("server:80");
Flds->Item[cdoURLProxyBypass]->Value = _variant_t("<local>");
Flds->Item[cdoURLGetLatestVersion]->Value =
_variant_t(VARIANT_TRUE);
Flds->Update(); iMsg->To = "\"SomeOne\" <[email protected]>";
iMsg->From = "\"Another\" <[email protected]>";
iMsg->Subject = "Here is a subject for the message."; /*
** attach an html file to message
** your local path goes in the "path"
** variable below
*/
try
{
filepath = _bstr_t(path) + _bstr_t("\\htmlfile.html");
iMsg->AddAttachment(filepath,"","");
}
catch (_com_error e)
{
//...
} /*
** Attach Word 2000 file to message
*/
try {
filepath = _bstr_t(path) + _bstr_t("\\wordfile.doc");
iMsg->AddAttachment(filepath,"","");
}
catch (_com_error e)
{
//...
}
/*
** Create MTHML body.
*/
try
{
iMsg->CreateMHTMLBody(
"http://mypage",
cdoSuppressAll,
"",
"");
}
catch (_com_error e)
{
//...
} iMsg->Send(); // save message
Stm = iMsg->GetStream();
Stm->SaveToFile(_bstr_t("message.eml"),adSaveCreateOverWrite); }
CoUninitialize();
}
[VBScript]
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iConf
Set iConf = CreateObject("CDO.Configuration")Dim Flds
Set Flds = iConf.FieldsWith Flds
' assume constants are defined within script file
.Item(cdoSendUsingMethod) = 2 ' cdoSendUsingPort
.Item(cdoSMTPServerName) = "[email protected]"
.Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Item(cdoURLProxyServer) = "server:80"
.Item(cdoURLProxyBypass) = "<local>"
.Item(cdoURLGetLatestVersion) = True
.Update
End WithWith iMsg
Set .Configuration = iConf
.To = """User A"" <[email protected]>"
.From = """User B"" <[email protected]>"
.Subject = "Hows it going? I've attached my web page"
.CreateMHTMLBody "http://mypage"
.AddAttachment "C:\files\mybook.doc"
.Send
End With
Creating and Sending a Message
The following example shows how to create a complete message that contains Hypertext Markup Language (HTML) and plain text versions and several attachments, and send it over the network. [Visual Basic]
Dim iMsg as New CDO.Message
Dim iConf as New CDO.ConfigurationDim Flds as ADODB.Fields
Set Flds = iConf.FieldsWith Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServerName) = "[email protected]"
.Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Item(cdoURLProxyServer) = "server:80"
.Item(cdoURLProxyBypass) = "<local>"
.Item(cdoURLGetLatestVersion) = True
.Update
End WithWith iMsg
Set .Configuration = iConf
.To = """User A"" <[email protected]>"
.From = """User B"" <[email protected]>"
.Subject = "Hows it going? I've attached my web page"
.CreateMHTMLBody "http://mypage"
.AddAttachment "C:\files\mybook.doc"
.Send
End With
[C++,IDL]
#import "d:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
#include <iostream.h>void main()
{
CoInitialize(NULL);
{
IMessagePtr iMsg(__uuidof(Message));
IBodyPartPtr iBp;
IBodyPartsPtr iBps;
_StreamPtr Stm;
_bstr_t filepath; IConfigurationPtr iConf(__uuidof(Configuration));
FieldsPtr Flds;
Flds = iConf->Fields;
Flds->Item[cdoSendUsingMethod]->Value =
_variant_t(cdoSendUsingPort);
Flds->Item[cdoSMTPServerName]->Value =
_variant_t("[email protected]");
Flds->Item[cdoSMTPConnectionTimeout]->Value = _variant_t((long)10);
Flds->Item[cdoSMTPAuthenticate]->Value = _variant_t(cdoBasic);
Flds->Item[cdoSendUserName]->Value = _variant_t("username");
Flds->Item[cdoSendPassword]->Value = _variant_t("password");
Flds->Item[cdoURLProxyServer]->Value = _variant_t("server:80");
Flds->Item[cdoURLProxyBypass]->Value = _variant_t("<local>");
Flds->Item[cdoURLGetLatestVersion]->Value =
_variant_t(VARIANT_TRUE);
Flds->Update(); iMsg->To = "\"SomeOne\" <[email protected]>";
iMsg->From = "\"Another\" <[email protected]>";
iMsg->Subject = "Here is a subject for the message."; /*
** attach an html file to message
** your local path goes in the "path"
** variable below
*/
try
{
filepath = _bstr_t(path) + _bstr_t("\\htmlfile.html");
iMsg->AddAttachment(filepath,"","");
}
catch (_com_error e)
{
//...
} /*
** Attach Word 2000 file to message
*/
try {
filepath = _bstr_t(path) + _bstr_t("\\wordfile.doc");
iMsg->AddAttachment(filepath,"","");
}
catch (_com_error e)
{
//...
}
/*
** Create MTHML body.
*/
try
{
iMsg->CreateMHTMLBody(
"http://mypage",
cdoSuppressAll,
"",
"");
}
catch (_com_error e)
{
//...
} iMsg->Send(); // save message
Stm = iMsg->GetStream();
Stm->SaveToFile(_bstr_t("message.eml"),adSaveCreateOverWrite); }
CoUninitialize();
}
[VBScript]
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iConf
Set iConf = CreateObject("CDO.Configuration")Dim Flds
Set Flds = iConf.FieldsWith Flds
' assume constants are defined within script file
.Item(cdoSendUsingMethod) = 2 ' cdoSendUsingPort
.Item(cdoSMTPServerName) = "[email protected]"
.Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Item(cdoURLProxyServer) = "server:80"
.Item(cdoURLProxyBypass) = "<local>"
.Item(cdoURLGetLatestVersion) = True
.Update
End WithWith iMsg
Set .Configuration = iConf
.To = """User A"" <[email protected]>"
.From = """User B"" <[email protected]>"
.Subject = "Hows it going? I've attached my web page"
.CreateMHTMLBody "http://mypage"
.AddAttachment "C:\files\mybook.doc"
.Send
End With