发送邮件
Posted tangdingkang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发送邮件相关的知识,希望对你有一定的参考价值。
效果图
main.cpp
1 #include <iostream> 2 #include "SendMail.h" 3 #include <string> 4 using namespace std; 5 6 int main() 7 { 8 char EmailContents[255]="From: "名字"<xxxxxxx@163.com> To:"; 9 char EmailTo[50]; 10 char subject[50]; 11 char content[50]; 12 printf("要发送的邮箱账号:"); 13 scanf("%s",EmailTo); 14 printf("你的标题:"); 15 scanf("%s",subject); 16 printf("你的内容:"); 17 scanf("%s",content); 18 19 strcat(EmailContents,EmailTo); 20 strcat(EmailContents," "); 21 strcat(EmailContents, "subject:"); 22 strcat(EmailContents, subject); 23 strcat(EmailContents, " "); 24 strcat(EmailContents, content); 25 strcat(EmailContents, " . "); 26 SendMail(EmailTo, EmailContents); 27 return 0; 28 }
SendMail.cpp
1 #include "SendMail.h" 2 3 #pragma comment(lib, "ws2_32.lib") 4 #include <string.h> 5 struct Base64Date6 6 { 7 unsigned int d4 : 6; 8 unsigned int d3 : 6; 9 unsigned int d2 : 6; 10 unsigned int d1 : 6; 11 }; 12 13 char ConvertToBase64(char uc) 14 { 15 if (uc < 26) 16 { 17 return ‘A‘ + uc; 18 } 19 if (uc < 52) 20 { 21 return ‘a‘ + (uc - 26); 22 } 23 if (uc < 62) 24 { 25 return ‘0‘ + (uc - 52); 26 } 27 if (uc == 62) 28 { 29 return ‘+‘; 30 } 31 return ‘/‘; 32 } 33 34 // base64的实现 35 void EncodeBase64(char *dbuf, char *buf128, int len) 36 { 37 struct Base64Date6 *ddd = NULL; 38 int i = 0; 39 char buf[256] = { 0 }; 40 char *tmp = NULL; 41 char cc = ‘