分享
 
 
 

用 SMTP 发送带验证带附件的邮件

王朝other·作者佚名  2008-05-30
窄屏简体版  字體: |||超大  

用 SMTP 发送带验证带附件的邮件 /*************************************************************

* smtp.cpp - Use SMTP to send an eMail with an Attachment and verify *

* Copyright (C) 2001-2002 by ShadowStar. *

* Use and modify freely. *

* http://shadowstar.126.com/ *

*************************************************************

*/

//---------------------------------------------------------------------------

#include

#include

#include

const int BASE64_MAXLINE = 76;

const char EOL[] = " ";

const char BASE64_TAB[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

"abcdefghijklmnopqrstuvwxyz0123456789+/";

const char HEADER[] =

"HELO support.com "

//"AUTH LOGIN " //+ BASE64 USER + BASE64 PASS

"MAIL FROM: chinansl@support.com "

"RCPT TO: shadowstar@support.com "

"DATA "

"FROM: chinansl@support.com "

"TO: shadowstar@support.com "

"SUBJECT: this is a test "

"Date: 2002-5-14 "

"X-Mailer: shadowstar's mailer "

"MIME-Version: 1.0 "

"Content-type: multipart/mixed; boundary="#BOUNDARY#" "

//"Content-Type: text/plain; charset=gb2312 "

" ";

const char CONTENT[] =

" --#BOUNDARY# "

"Content-Type: text/plain; charset=gb2312 "

"Content-Transfer-Encoding: quoted-printable "

" "

"/*************************************************************"

" * smtp.cpp - Use SMTP to send an eMail with an Attachment and verify *"

" * Copyright (C) 2001-2002 by ShadowStar. *"

" * Use and modify freely. *"

" * http://shadowstar.126.com/ *"

" *************************************************************"

" */ "

" ";

const char ATT_HEADER[] =

" --#BOUNDARY# "

"Content-Type: application/octet-stream; name=smtp.exe "

"Content-Disposition: attachment; filename=smtp.exe "

"Content-Transfer-Encoding: base64 "

" ";

//---------------------------------------------------------------------------

int ANSIToBase64(const char *szInANSI, int nInLen, char *szOutBase64, int nOutLen);

int main(int argc, char* argv[])

{

WSADATA wsaData;

int SockFD;

struct sockaddr_in ServAddr;

char buf[0x100];

int x;

FILE *fp;

char *aatt = new char[0x400000];

char *batt = new char[0x555556];

WSAStartup(MAKEWORD(2,2), %26amp;wsaData);

LPHOSTENT pHost = gethostbyname("172.16.234.111");

SockFD = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

ServAddr.sin_family = AF_INET;

ServAddr.sin_addr.s_addr = *(ULONG *)pHost-h_addr_list[0];

ServAddr.sin_port = htons(25);

connect(SockFD, (struct sockaddr *)%26amp;ServAddr, sizeof(ServAddr));

//send HEADER

send(SockFD, HEADER, strlen(HEADER), 0);

//send CONTENT

send(SockFD, CONTENT, strlen(CONTENT), 0);

//send ATT_HEADER

send(SockFD, ATT_HEADER, strlen(ATT_HEADER), 0);

//read attachment

fp = fopen(argv[0], "rb");

fseek(fp, 0, 2);

x = ftell(fp);

if (x 0x400000)

x = 0;

rewind(fp);

fread(aatt, x, 1, fp);

fclose(fp);

x = ANSIToBase64(aatt, x, batt, 0x555556);

//send base64 attachment

send(SockFD, batt, x, 0);

send(SockFD, ". ", strlen(". "), 0); //end

send(SockFD, "QUIT ", strlen("QUIT "), 0); //quit

closesocket(SockFD);

WSACleanup();

delete []aatt;

delete []batt;

return 0;

}

//---------------------------------------------------------------------------

int ANSIToBase64(const char *szInANSI, int nInLen, char *szOutBase64, int nOutLen)

{

//Input Parameter validation

if ((szInANSI == NULL) || (nInLen == 0) || (szOutBase64 == NULL) || (nOutLen == 0))

return 0;

if (nOutLen

return 0;

//Set up the parameters prior to the main encoding loop

int nInPos = 0;

int nOutPos = 0;

int nLineLen = 0;

int c1, c2, c3;

int i;

// Get three characters at a time from the input buffer and encode them

for (i=0; i

{

//Get the next 2 characters

c1 = szInANSI[nInPos++] %26amp; 0xFF;

c2 = szInANSI[nInPos++] %26amp; 0xFF;

c3 = szInANSI[nInPos++] %26amp; 0xFF;

//Encode into the 4 6 bit characters

szOutBase64[nOutPos++] = BASE64_TAB[c1 2];

szOutBase64[nOutPos++] = BASE64_TAB[((c1 4)) %26amp; 0x3F];

szOutBase64[nOutPos++] = BASE64_TAB[((c2 6)) %26amp; 0x3F];

szOutBase64[nOutPos++] = BASE64_TAB[c3 %26amp; 0x3F];

nLineLen += 4;

//Handle the case where we have gone over the max line boundary

if (nLineLen BASE64_MAXLINE - 4)

{

szOutBase64[nOutPos++] = EOL[0];

szOutBase64[nOutPos++] = EOL[1];

nLineLen = 0;

}

}

// Encode the remaining one or two characters in the input buffer

switch (nInLen % 3)

{

case 0:

{

szOutBase64[nOutPos++] = EOL[0];

szOutBase64[nOutPos++] = EOL[1];

break;

}

case 1:

{

c1 = szInANSI[nInPos] %26amp; 0xFF;

szOutBase64[nOutPos++] = BASE64_TAB[(c1 %26amp; 0xFC) 2];

szOutBase64[nOutPos++] = BASE64_TAB[((c1 %26amp; 0x03)

szOutBase64[nOutPos++] = '=';

szOutBase64[nOutPos++] = '=';

szOutBase64[nOutPos++] = EOL[0];

szOutBase64[nOutPos++] = EOL[1];

break;

}

case 2:

{

c1 = szInANSI[nInPos++] %26amp; 0xFF;

c2 = szInANSI[nInPos] %26amp; 0xFF;

szOutBase64[nOutPos++] = BASE64_TAB[(c1 %26amp; 0xFC) 2];

szOutBase64[nOutPos++] = BASE64_TAB[((c1 %26amp; 0x03) 4)];

szOutBase64[nOutPos++] = BASE64_TAB[((c2 %26amp; 0x0F)

szOutBase64[nOutPos++] = '=';

szOutBase64[nOutPos++] = EOL[0];

szOutBase64[nOutPos++] = EOL[1];

break;

}

default:

{

return 0;

}

}

szOutBase64[nOutPos] = 0;

return nOutPos;

}

,

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有