資源簡介
jmail發送郵件的例子,用126郵箱測試過可用。
代碼片段和文件信息
#include?“stdafx.h“
#include?
#import?“jmail.dll“?//?The?path?to?the?jmail.dll?file?here!
#include?“stdio.h“
//需要修改的參數
const?char?*mailserver =?“smtp.126.com“; //郵箱服務器
const?char?*sender =?“xyz@126.com“; //郵箱帳號
const?char?*PassWord =?“123465“; //郵箱密碼
const?char?*recipient =?“xyz@126.com“; //接收方的郵箱
const?char?*senderName =?“mike“;
const?char?*subject =?“Hello?JMail!“;
const?char?*body =?“This?message?was?sent?with?JMail?version?4.0\n“;
int?main(int?argc?char*?*argv)
{
/* //注冊DLL
char?Parm_JMAIL[MAX_PATH];
sprintf(Parm_JMAIL?“?/s?\“%s\““?“jmail.dll“);
::ShellExecute(?NULL?““?“regsvr32“?Parm_JMAIL?“.“?SW_HIDE?);
*/
//
CoInitialize(NULL);
{
? try
{
/* //?jmail::ISpeedMailerPtr?is?generated?and?declared?by?the?#import?directive.
jmail::ISpeedMailerPtr?spJMail(“JMail.SpeedMailer“);
//?Ok?send?the?mail.
HRESULT?ret?=?spJMail->SendMail(?sender?recipient?subject?body?mailserver?);
*/
{
? jmail::IMessagePtr?jm(“JMail.Message“);
? jm->Silent?=?true;//?當Silent屬性設為False時,出錯時會拋出異常;當Silent屬性設為True時,出錯時不會拋出異常,執行Send方法后,直接返回True?or?False。
? jm->Logging?=?true;
? jm->Subject?=?subject; //?郵件主題
? jm->Charset?=?“gb2312“;
? jm->ContentType?=?“text/html“;
? jm->From?=?sender; //郵件發送端
? jm->ReplyTo?=?““;
? jm->FromName?=?senderName; //郵件發送端名稱
? jm->MailServerUserName?=?sender; //郵件發送端服務器用戶名
? jm->MailServerPassWord?=?PassWord; //郵件發送端服務器密碼
? jm->Body?=?body; //郵件正文
? jm->AddRecipient(recipient?““?““); //郵件接收端
? jm->Send(mailserverfalse);?
jm->Close();
jm->Release();
? }
}
catch(?_com_error?&?E)
{
std::cerr<“Error:?0x“?< < ;
}
}
CoUninitialize();
/* //反注冊DLL
sprintf(Parm_JMAIL?“?/s?/u?\“%s\““?“jmail.dll“);
::ShellExecute(?NULL?““?“regsvr32“?Parm_JMAIL?“.“?SW_HIDE?);
*/
system(“pause“);
return?0;
}
- 上一篇:ASP.NET Technique 外文翻譯
- 下一篇:NFC驅動代碼PN532
評論
共有 條評論