资源简介
SMTP邮件发送客户端.rar
代码片段和文件信息
#include
#include
#include
#include
#pragma comment(lib“ws2_32.lib“)
using namespace std;
struct base64Date6
{
unsigned int d4:6;
unsigned int d3:6;
unsigned int d2:6;
unsigned int d1:6;
};
// 协议中加密部分使用的是base64方法
char ConvertTobase64(char c6);
void Encodebase64(char*dbufchar*buf128int len);
void SendMail(char*emailchar*body);
int OpenSocket(struct sockaddr *addr);
char ConvertTobase64(char uc)
{
if(uc <26)
{
return‘A‘+uc;
}
if(uc <52)
{
return‘a‘+(uc -26);
}
if(uc <62)
{
return‘0‘+(uc -52);
}
if(uc ==62)
{
return‘+‘;
}
return‘/‘;
}
// base64的实现
void Encodebase64(char* dbufchar* buf128int len)
{
struct base64Date6* ddd =NULL;
int i =0;
char buf[256]={0};
char* tmp =NULL;
char cc =‘\0‘;
memset(buf0256);
strcpy_s(buf256buf128);
for(i =1;i <=len/3;i++)
{
tmp =buf +(i-1)*3;
cc =tmp[2];
tmp[2]=tmp[0];
tmp[0]=cc;
ddd =(struct base64Date6*)tmp;
dbuf[(i-1)*4+0]=ConvertTobase64((unsigned int)ddd->d1);
dbuf[(i-1)*4+1]=ConvertTobase64((unsigned int)ddd->d2);
dbuf[(i-1)*4+2]=ConvertTobase64((unsigned int)ddd->d3);
dbuf[(i-1)*4+3]=ConvertTobase64((unsigned int)ddd->d4);
}
if(len %3==1)
{
tmp =buf +(i-1)*3;
cc =tmp[2];
tmp[2]=tmp[0];
tmp[0]=cc;
ddd =(struct base64Date6*)tmp;
dbuf[(i-1)*4+0]=ConvertTobase64((unsigned int)ddd->d1);
dbuf[(i-1)*4+1]=ConvertTobase64((unsigned int)ddd->d2);
dbuf[(i-1)*4+2]=‘=‘;
dbuf[(i-1)*4+3]=‘=‘;
}
if(len%3==2)
{
tmp =buf+(i-1)*3;
cc =tmp[2];
tmp[2]=tmp[0];
tmp[0]=cc;
ddd =(struct base64Date6*)tmp;
dbuf[(i-1)*4+0]=ConvertTobase64((unsigned int)ddd->d1);
dbuf[(i-1)*4+1]=ConvertTobase64((unsigned int)ddd->d2);
dbuf[(i-1)*4+2]=ConvertTobase64((unsigned int)ddd->d3);
dbuf[(i-1)*4+3]=‘=‘;
}
return;
}
// 发送邮件
void SendMail(char* emailchar* bodychar *source)
{
int sockfd ={0};
char buf[1500]={0};
char rbuf[1500]={0};
char login[128]={0};
char pass[128]={0};
WSADATA WSAData;
struct sockaddr_in their_addr ={0};
WSAStartup(MAKEWORD(22)&WSAData);
memset(&their_addr0sizeof(their_addr));
their_addr.sin_family =AF_INET;
their_addr.sin_port =htons(25);
hostent*hptr =gethostbyname(“smtp.sina.com“);
memcpy(&their_addr.sin_addr.S_un.S_addrhptr->h_addr_list[0]hptr->h_length);
printf(“IP of smpt.smtp.com is : %d:%d:%d:%d\n“
their_addr.sin_addr.S_un.S_un_b.s_b1
their_addr.sin_addr.S_un.S_un_b.s_b2
their_addr.sin_addr.S_un.S_un_b.s_b3
their_addr.sin_addr.S_un.S_un_b.s_b4);
// 连接邮件服务器,如果连接后没有响应,则2 秒后重新连接
sockfd =OpenSocket((struct sockaddr *)&their_addr);
memset(rbuf01500);
while(recv(sockfdrbuf15000)==0)
{
cout<<“reconnect...“< Sleep(2);
sockfd =OpenSocket((struct sockaddr *)&their_addr);
memset(rbuf01500);
}
cout<
// EHLO
memset(buf01500);
sprintf_s(buf1500“EHLO HYL-PC\r\n“);
send(sockfdbufs
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11197 2013-11-11 10:49 SMTP邮件发送客户端\SMTP邮件发送.cpp
文件 139 2013-11-11 10:52 SMTP邮件发送客户端\说明.txt
目录 0 2013-11-11 10:50 SMTP邮件发送客户端
----------- --------- ---------- ----- ----
11336 3
相关资源
- mahjong.zip
- 博览网教学视频.txt
- rar(39)
- 20190115-5c3d91493c3e53.25395649.rar
- 大数据_scala教程地址.txt
- EGM96的计算含有坐标转换及其他参数计
- netty.txt
- 明星人名大全合计5万5千个一行一个
- datastructureandalgorithmanalysisincsolution.p
- 百度云网盘解除限速工具.zip
- 小程序全套视频.txt
- 网课查课接口代刷网专用.zip
- visio2016.txt
- testQuazip.zip
- 视觉SLAM十四讲视频百度云.txt
- u011922164_9607053.txt
- surpac转ansys.rar
- M_51NET.rar
- PSO_path_planning-master.zip
- u011803118_6003703.xls
- QQ盗号源码.e
- arcgisforjs自定义鼠标样式.zip
- 全套机器学习深度学习——链接.txt
- 老虎微信淘宝客v5.99.46代理2.99.3.zip
- DDos.rar265452
- 7qds8n.rar
- u011541897_7733925.zip
- vi(1)
- 将QT界面做成dll在qt其他程序中调用
- 视觉SLAM十四讲全集视频链接视频百度
评论
共有 条评论