C++调用Smtp发送邮件代码
[来源] 达内 [编辑] 达内 [时间]2012-08-30
[代码] [C/C++]代码
01 void test_smtp_by_rrrfff()
02 {
03 SmtpClient smtp;
04 if(!smtp.Connect(T("smtp.163.com"), 25))
05 {
06 //error
07 //check socket or smtp.ResponseString
08 return;
09 }
10 if(!smtp.Login(T("username"), T("password")))
11 {
12 //error
13 //check smtp.ResponseString
14 return;
15 }
16
17 MailMessage mailmsg;
18 mailmsg.From = T("username@163.com");
19 mailmsg.Subject = T("hello");
20 mailmsg.Body = T("rlib");
21 mailmsg.Sender = T("username@163.com");
22 MailAddress mailaddr;
23 mailaddr.Address = T("630235622@qq.com");
24 ->Add(mailaddr);
25 Attachment attach;
26 attach.ContentType = "application/octet-stream";
27 attach.Encoding = "Base64";
28 = "附件名称";
29 attach.Path = "附件地址";
30 mailmsg.Attachments->Add(attach);
31
32 if(!smtp.Send(mailmsg))
33 {
34 //error
35 //check smtp.ResponseString
36 return;
37 }
38 //smtp.Logout();
39 }