int SendMail(char *content){ sMailInfo smailInfo; memset(&smailInfo, 0, sizeof(sMailInfo)); smailInfo.m_pcUserName = sender; smailInfo.m_pcUserPassWord = senderpwd; smailInfo.m_pcSenderName = sender; smailInfo.m_pcSender = sender; smailInfo.m_pcReceiver = receiver; smailInfo.m_pcTitle = sendtitle; smailInfo.m_pcBody = content; smailInfo.m_pcIPAddr = serverip; smailInfo.m_pcIPName = servername; CSendMail mail; if(mail.SendMail(smailInfo)){ //printf("Send mail success\n"); return 0; }else{ //最好写个日志 if(flog == NULL) flog = fopen("log.txt", "a"); if(flog){ fprintf(flog, "[Send mail failed]\n%s", content); fflush(flog); } return 1; } return 0; }
int main() { CSendMail sMailer; // freopen("F://mailfile//out.txt","w+",stdout); sMailer.setServerName("smtp.126.com"); //邮箱smtp,如"smtp.126.com" sMailer.setUserName("userName"); //邮箱账号名,如"****@126.com" sMailer.setUserPwd("userPwd"); //邮箱密码 sMailer.setSenderName("陈家喵"); //发件人名字 sMailer.setSenderAddress("*****@*****.**"); //发送邮箱地址,填你账号的地址,上面的邮箱账号名"****@126.com" sMailer.setReceiver("柯林林","*****@*****.**"); //添加邮件接收者 sMailer.addReceiver("sixbeauty","*****@*****.**"); sMailer.AddFilePath("F:\\mailfile\\out.txt"); //添加附件 // sMailer.AddFilePath("F:/mailfile/libcurl.exp"); //添加附件 //发送第一份邮件 if(sMailer.Connent()) //每次发邮件前都需要connect { if(sMailer.SendMail("CMailSender:阿垃垃圾君","你想快速发家致富吗?你想一夜成名吗?访问 http://www.sb.com")) //第一个字符串是邮件标题,第二个是邮件内容 cout<<"邮件发送完成!"; } //发送第二份邮件 if(sMailer.Connent()) //每次发邮件前都需要connect { std::string title,content; title="测试邮件part_2"; content="柯林是个大八嘎!"; if(sMailer.SendMail(title,content)) //第一个字符串是邮件标题,第二个是邮件内容 cout<<"邮件发送完成!"; } return 0; }