CSDN博客

img dgyanyong

利用C++Builder中的NMSMTP发送电子邮件(能通过邮箱的验证)

发表于2004/9/13 21:45:00  4637人阅读

分类: C++

在头文件里加上

#include “idcoder3to4.hpp“

用Base64Encode()函数对用户名和密码编码

NMSMTP1->Host = "smtp.163.com";     //SMTP主机名
NMSMTP1->UserID = "dgyanyong";      //用户名
NMSMTP1->PostMessageA->FromAddress = "dgyanyong@163.com";   //发信人地址
NMSMTP1->PostMessageA->ToAddress->Clear();     //收信人地址清空
NMSMTP1->PostMessageA->ToAddress->Text = "dgyanyong@sina.com"; //收信人地址
NMSMTP1->PostMessageA->ToCarbonCopy->Text = "dgyanyong@chinaren.com"; //抄送地址
NMSMTP1->PostMessageA->ToBlindCarbonCopy->Text = "dgyanyong@163.com"; //暗送地址
NMSMTP1->PostMessageA->Subject = "test message";      //邮件标题
NMSMTP1->PostMessageA->Body->Add("this is a test message!"); //邮件内容
NMSMTP1->PostMessageA->Attachments->Text = "C://qq.doc";      //邮件附件
NMSMTP1->PostMessageA->LocalProgram = "SendMail";   
NMSMTP1->Connect();
if (CheckBox1->Checked == true)
{
  AnsiString userName = Base64Encode("dgyanyong");  //将用户名编码
  AnsiString password = Base64Encode("dgyanyong"); //将密码编码
  NMSMTP1->Transaction("auth login");  //开始验证
  NMSMTP1->Transaction(userName);
  NMSMTP1->Transaction(password);
}
NMSMTP1->SendMail();
Memo1->Lines->Add("发送邮件成功");
NMSMTP1->Disconnect();

上述邮箱、163邮箱的用户名和密码均属虚构,只是做个范例,用户可以根据自己的需要设定。

0 0

相关博文

我的热门文章

img
取 消
img