资源简介
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“ << std::hex << E.Error() << std::endl
<< E.ErrorMessage() << std::endl
;
}
}
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
评论
共有 条评论