|
工作需要,整合了一个发送邮件的小例子。此代码在Linux和windows下测试通过。
感谢弄香花满衣的贡献。
完整代码见附件
- #include "stdafx.h"
- #include "smtp.h"
- int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
- {
- int ret = 0;
- unsigned char *mail = NULL;
- const unsigned char *mailSubject = (const unsigned char*)"test";
- const unsigned char *mailBody = (const unsigned char*)"hello smtp!!";
- const unsigned char *fromMailAddr= (const unsigned char*)"123456@163.com";
- const unsigned char *mailPasswd= (const unsigned char*)"123456";
- const unsigned char *toMailAddr= (const unsigned char*)"123456@163.com";
- const unsigned char *smtpUrl = (const unsigned char*)"smtp.163.com";
- for(int i = 0; i < 10; i++)
- {
- mail = (unsigned char*) calloc(1, 1);
- ret = mailText(&mail, fromMailAddr, toMailAddr, mailSubject, mailBody);
- ret = mailEnd(&mail);
- //SMTP_Print6("\r\n%s \r\n", mail);
- printf("\r\nprepare email OK ...\r\n");
- ACE_HANDLE fd;
- ret = connectSmtp(fd, smtpUrl, SMTP_PORT);
- if(ret == 0)
- {
- printf("connect OK ...\r\n");
- }
- ret = authEmail(fd, fromMailAddr, mailPasswd);
- printf("auth OK ...\r\n");
- ret = sendEmail(fd, fromMailAddr, toMailAddr, (const unsigned char *)mail, (const int)strlen((const char *)mail));
- printf("send OK ...\r\n");
-
- free(mail);
- }
- getchar();
- return 0;
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?用户注册
×
|