spacer.png, 0 kB
spacer.png, 0 kB
Home arrow All Articles arrow Internet Anonymity arrow SMTP protocol and how to use it in C and Winsock

Subscribe to our news and articles by RSS or by email
SMTP protocol and how to use it in C and Winsock Print E-mail

smtp protocol is "Simple Mail Transfer Protocol", this protocol is better then others cause its more reliable.

Its independent to the sub system and requires flux of reliable data and working through port 25.

the most important trait is that this protocol has an ability to send mail across service transmission environmental.

lets see how it works:

after connected to the server you get a response number 220, the first thing you have to do after that is to send this

command:

HELO <domain>

its an announcement of identification that sent to the server and the server returns you response number 250 <name_of_the_host>

when name_of_the_host will be the name of the server that through it we send the mail.

Now you need to announce from which mail you sending it:

MAIL FROM:<reverse-path><CRLF>

CRLF for those who dont know is CR is '\r' and LF is '\n' ('\r' is end of line and '\n' start new line);

and then you get response number 250.

RCPT TO: <forward-path><CRLF>
to who you're sending the damn mail?

the response is 250 as usual.

of course you get 250 if everything goes well.

now the data of the mail comes here:

DATA<CRLF>

do not! :P dont change it! send it like that

and then you need to recieve 354 response. That says Start Mail Input

then

FROM: This e-mail address is being protected from spam bots, you need JavaScript enabled to view it <CRLF>

no response

Subject: Hello bud<CRLF>

no response

then you enter the contents of the mail :)

hey my name is c1pagr and im more cool then you are :)<CRLF>.<CRLF>

the point tells to the server thats all for now.

then you get response 250 OK

and then you need to enter

RSET<CRLF>

NOOP<CRLF>

QUIT<CRLF>

and to all of them you need to get response of 250 OK

QUIT tells the server cya!

NOOP clears the server buffers.

 

the responses from the server for each command:

S(Success),F(Failure),E(Eror)

CONNECTION ESTABLISHMENT

S: 220

F: 421

HELO

S: 250

E: 500, 501, 504, 421

MAIL S: 250

F: 552, 451, 452

E: 500, 501, 421

RCPT

S: 250, 251

F: 550, 551, 552, 553, 450, 451, 452

E: 500, 501, 503, 421

DATA

I: 354 -> data -> S: 250

F: 552, 554, 451, 452

F: 451, 554

E: 500, 501, 503, 421

 

RSET

S: 250

E: 500, 501, 504, 421

NOOP

S: 250

E: 500, 421

QUIT

S: 221

E: 500

 

 

Code in C:

//after connecting to the server ...

char*recvbuf = (char *)maloc(sizeof(char)*256);

char*recvbuf_tmp = (char *)maloc(sizeof(char)*256);

charsendbuf[256]= "";

int er =0;

recv(msock,recvbuf_tmp,256,0);

Sleep(500);

if(*(recvbuf_tmp)=='4'| *(recvbuf_tmp)=='5')

{

er =1;

}

if(*(recvbuf_tmp)=='2'&&*(recvbuf_tmp+1)=='2'&&*(recvbuf_tmp+2)=='0' && er==0)

{

puts(recvbuf_tmp);

}

 

strcpy(sendbuf,"HELO ");

strcat(sendbuf,"bezeqint.net\r\n");

send(msock,sendbuf,strlen(sendbuf),0);

Sleep(500);

recv(msock,recvbuf,256,0);

if(*(recvbuf)=='2' &&*(recvbuf+1)=='5' && *(recvbuf+2)== '0' && er==0)

{

strcpy(sendbuf, "MAIL FROM:< This e-mail address is being protected from spam bots, you need JavaScript enabled to view it >\r\n");

send(msock,sendbuf,strlen(sendbuf),0);

Sleep(500);

recv(msock,recvbuf_tmp,256,0);

}

if(*recvbuf_tmp=='4' | *recvbuf_tmp=='5')

{

er=1;

}

if(*recvbuf_tmp=='2' && *(recvbuf_tmp+1)=='5'&& *(recvbuf_tmp+2)=='0'&& er == 0)

{

puts(recvbuf);

putchar('\n');

strcpy(sendbuf, "RCPT TO:< This e-mail address is being protected from spam bots, you need JavaScript enabled to view it >\r\n");

send(msock,sendbuf,strlen(sendbuf),0);

Sleep(500);

recv(msock,recvbuf_tmp,256,0);

}

if(*(recvbuf_tmp)=='2' &&*(recvbuf_tmp+1)=='5' &&*(recvbuf_tmp+2)=='0' &&er==0)

{

strcpy(sendbuf,"DATA\r\n\r\n");

send(msock,sendbuf,strlen(sendbuf),0);

Sleep(500);

recv(msock,recvbuf_tmp,256,0);

}

if(*(recvbuf_tmp)=='4' |*(recvbuf_tmp)=='5')

{

er=1;

}

if(*(recvbuf_tmp)=='3' &&*(recvbuf_tmp+1)=='5' &&*(recvbuf_tmp+2)=='4' &&er==0)

{

puts(recvbuf_tmp);

printf("\n\nstartingwith sendingdata: \n");

putchar('\n');

strcpy(sendbuf, "From: <");

strcat(sendbuf,"blabla"); / (:
×?כל ×?בשהמ ×?ושרל ×?ילוכי×?ת×? הפ

strcat(sendbuf,">\x0d\x0a");

send(msock,sendbuf,strlen(sendbuf),0);

Sleep(500);

strcpy(sendbuf,"Subject: We want peace\x0d\x0a"); /
הלטסב הפ בשוי ×?שונה

send(msock,sendbuf,strlen(sendbuf),0);

Sleep(500);

//here you copy the contents to the buffer and send it on the next line :)

strcpy(sendbuf, "Thisisa virus! andwe don'twant peace\x0d\x0a.\x0d\x0a"); /

 

 

send(msock,sendbuf,strlen(sendbuf),0);

Sleep(500);

recv(msock,recvbuf_tmp,256,0);

}

 

if(*recvbuf_tmp=='5' | *recvbuf_tmp=='4')

{

er =1;

printf("\ncan't send data");

}

if(*(recvbuf_tmp)== '2' && *(recvbuf_tmp+1)=='5' && *(recvbuf_tmp+2)=='0' && er==0)

{

printf("\n\n\n\nSENDED.\n\n");

}

strcpy(sendbuf,"QUIT\x0d\x0a");

send(msock,sendbuf,strlen(sendbuf),0);

printf("Closing connection .finished with sex:) \n\n");

getchar();

}

 

 

 

 

hope you learned something new

yours forever,

c1pagr

(use it wwwize :P )


Related Items:

 
< Prev   Next >
spacer.png, 0 kB
spacer.png, 0 kB
spacer.png, 0 kB