怎样写发邮件的代码? 急,急急!!!

killhack 2003-05-08 09:20:35
我想向goog@163.com 发一份邮件,邮件内容为: 你好,我正在写程序


这怎写代马呢,现在的服务器都需要认证哟,高手帮我搞几句,谢谢
...全文
95 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
meCAD 2003-05-10
  • 打赏
  • 举报
回复
有两个控件:TIdMessage:IdMsgSend, TIdSMTP:SMTP
/发送邮件
//注:发送的SMTP属性通过SMTP_Setup函数设置了
//参数:in:cTo,收件人
// cCc 抄送
// cBcc 暗抄
// cSubject 主题
// cBody 内容
// cAttachList 发送的附件(以\n分割)
// OUT: Msg 返回错误信息
//返回值 0: 成功发送
// -1:失败,参见Msg信息
// -2: 没有先设置SMTP发送属性
int __fastcall TM::SendMail(const char * cTo, const char * cCc, const char * cBcc,\
const char* cSubject, const char * cBody, const char* cAttachList,\
char * cMsg)
{
int iRet=0;
if(!SetupOk)
return -2;

IdMsgSend->Clear(); //清除,否则包含有上一条的信息

IdMsgSend->ContentType = ContentType;
IdMsgSend->From->Text = LocalMail;
if (ReturnReciept)
{//{We set the recipient to the From E-Mail address }
IdMsgSend->ReceiptRecipient->Text = IdMsgSend->From->Text;
}
else
{// {indicate that there is no receipt recipiant}
IdMsgSend->ReceiptRecipient->Text = "";
}

IdMsgSend->Recipients->EMailAddresses = cTo; //{ To: header }
IdMsgSend->Subject = cSubject; //{ Subject: header }
IdMsgSend->CCList->EMailAddresses = cCc;// {CC}
IdMsgSend->BccList->EMailAddresses = cBcc; //{BCC}

IdMsgSend->Priority = TIdMessagePriority(Priority); // { Message Priority }
IdMsgSend->Body->Text = String(cBody);

if(strlen(cAttachList))
{
TStringList * sl= new TStringList;
sl->Text=String(cAttachList);
for(int i=0;i<sl->Count;i++)
{
IdMsgSend->MessageParts->Add();
new TIdAttachment(IdMsgSend->MessageParts,sl->Strings[i]);
}
delete sl;
}
if(!SMTP->Connected())
{
try
{
SMTP->Connect();
}
catch(Exception &e)
{
strcpy(cMsg,"连接SMTP服务器失败!错误信息:");
strcat(cMsg,e.Message.c_str());
iRet = -1;
return iRet;
}
}
if(SMTP->Connected())
{
try
{
SMTP->Send(IdMsgSend);
}
catch(Exception &e)
{
strcpy(cMsg,e.Message.c_str());
iRet = -1;
}
}
else
{
strcpy(cMsg,"连接SMTP服务器失败!");
iRet = -1;
}
return iRet;
}

//设置发送的SMTP属性
//参数:in:cHost,SMTP服务器地址
// iPort, SMTP端口
// cLocalMail 发件人的邮箱
// iAuth 是否认证 0,不认证,1认证
// cUsername 认证用户名
// cPassword 认证密码
// OUT: 无
//返回值 0: 成功设置
// -1:失败,缺少属性
int __fastcall TM::SMTP_Setup(const char * cHost, const int iPort, const char *cLocalMail,\
const int iAuth, const char * cUsername, const char *cPassword)
{
int iRet=0;
if(SMTP->Connected())
SMTP->Disconnect();
SMTP->Host = String(cHost);
SMTP->Port = iPort;
this->LocalMail = String(cLocalMail);

switch (iAuth)
{
// {authentication settings}
case 0:
SMTP->AuthenticationType = atNone;
break;
case 1:
SMTP->AuthenticationType = atLogin; //{Simple Login}
break;
};
SMTP->Username = cUsername;
SMTP->Password = cPassword;

SetupOk = true;
return iRet;
}


来自chinabcb.com
SharpKing515 2003-05-09
  • 打赏
  • 举报
回复
回复人: Atomictry(天影) ( ) 信誉:100 2003-05-08 16:22:00 得分:0


上面那个身份验证格式是对的。只是没有Base64Encod()这个编码函数,你自己写一个编码函数就一定能搞出来了,不信你试试。


//--------------------------------------------------
在indyMisc中有这么一对:
IdBase64Encoder1
IdBase64Decoder1
Atomictry 2003-05-09
  • 打赏
  • 举报
回复
SharpKing515(不穿内裤):
又见了:)
果然嘛,害得我白写了编码解码函数。
我都想给你分了。
wolong1 2003-05-09
  • 打赏
  • 举报
回复
帮你up,多给点分
恭喜楼主发财!!!!!!!
killhack 2003-05-08
  • 打赏
  • 举报
回复
顶,那个给些代码撒
SharpKing515 2003-05-08
  • 打赏
  • 举报
回复
同意楼上。。。。。
用API。。。。

呵呵。。。
zbc 2003-05-08
  • 打赏
  • 举报
回复
如果你只是随便写着玩,你还可以用TNMSMTP和TNMPOP3组件,如果是要好好的写的话,呵呵,强烈建议你不要用这些组件为妙!
killhack 2003-05-08
  • 打赏
  • 举报
回复
net205 2003-05-08
  • 打赏
  • 举报
回复
没写过,帮你顶!!!!!!!!
huang_jihua 2003-05-08
  • 打赏
  • 举报
回复
搜索一下以前的帖子很多的。我贴一个给你看:
回复人: hotxu(hotxu) ( ) 信誉:100 2002-5-8 18:51:57 得分:20 Top

用FastNet的NMSMTP组件也可以做支持身份验证的邮件发送程序,只要在NMSMTP的Connect事件里加几句就行了。

void __fastcall TFormMain::NMSMTP1Connect(TObject *Sender)
{
char EncName[64],EncPsw[64];
memset(EncName,0,64);//注意,一定要清零。
memset(EncPsw,0,64);
Base64Encod(Edit4->Text.c_str(),Edit4->Text.Length(),EncName);
Base64Encod(Psw->Text.c_str(),Psw->Text.Length(),EncPsw);
StatusBar1->SimpleText = "Connected";
if(NMSMTP1->ReplyNumber==250)
{
NMSMTP1->Transaction("auth login");
// ::MessageBox(this->Handle,"Auth start!","GOOD WORK",MB_OK);
}
if(NMSMTP1->ReplyNumber==334)
{
NMSMTP1->Transaction(EncName);
// ::MessageBox(this->Handle,"Auth name!","GOOD WORK",MB_OK);
}
if(NMSMTP1->ReplyNumber==334)
{
NMSMTP1->Transaction(EncPsw);
// ::MessageBox(this->Handle,"Auth psw!","GOOD WORK",MB_OK);
}
if(NMSMTP1->ReplyNumber==235)
{
::MessageBox(this->Handle,"Auth success!","GOOD WORK",MB_OK);
}

}




chifengwatch 2003-05-08
  • 打赏
  • 举报
回复
http://vip.6to23.com/NowCan1/code/smtpauth.zip
Atomictry 2003-05-08
  • 打赏
  • 举报
回复
上面那个身份验证格式是对的。只是没有Base64Encod()这个编码函数,你自己写一个编码函数就一定能搞出来了,不信你试试。

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧