首先要导入jmail.dll
#import "jmail.dll"
还要初始化COM套间
CoInitialize(NULL);
调用代码如下
typedef HRESULT (__stdcall* pfnDllGetClassObject)(REFCLSID, REFIID, void**);
HINSTANCE hDllInst = LoadLibrary(_T("jmail.dll"));
pfnDllGetClassObject fnDllGetClassObject = (pfnDllGetClassObject)GetProcAddress(hDllInst, "DllGetClassObject");
if (fnDllGetClassObject != NULL)
{
IClassFactory* lpClassFactory = NULL;
HRESULT hr = (fnDllGetClassObject)(__uuidof(jmail::Message), IID_IClassFactory, (void**)&lpClassFactory);
if (SUCCEEDED(hr) && (lpClassFactory != NULL))
{
IUnknown* lpUnknown = NULL;
hr = lpClassFactory->CreateInstance(NULL, __uuidof(jmail::IMessage), (void**)&lpUnknown);
if (SUCCEEDED(hr) && (lpUnknown != NULL))
{
jmail::IMessagePtr MyMessage(lpUnknown);
//不抛出错误
MyMessage->PutSilent(VARIANT_TRUE);
MyMessage->PutISOEncodeHeaders(VARIANT_TRUE);
//字符集,缺省为"US-ASCII"
MyMessage->PutCharset(_T("GB2312"));
//发件人姓名
MyMessage->PutFromName(_T("test"));
//发件人邮箱
MyMessage->PutFrom(_T("***@***.com"));
//发件人邮件用户名
MyMessage->PutMailServerUserName(_T("***"));
//发件人邮件密码
MyMessage->PutMailServerPassWord(_T("***"));
//设置邮件标题
MyMessage->PutSubject(_T("邮件标题"));
//邮件内容
MyMessage->PutBody(_T("邮件内容"));
//发送对象
MyMessage->AddRecipient(_T("***@***.com"), _T(""), _T(""));
//Jmail发送的方法
MyMessage->Send(_T("smtp.***.com"), VARIANT_FALSE);
MyMessage->Close();
MyMessage.Release();
}
lpClassFactory->Release();
}
}
FreeLibrary(hDllInst);
posted on 2010-10-09 13:44
张志松 阅读(3258)
评论(3) 编辑 收藏 引用 所属分类:
VC/MFC