1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
void suppr_n(char *ptr)
{
char *p=strchr(ptr,'\n'); //recherche le '\n' dans ptr
if(p!=NULL)
*p=0;
}
int main(void)
{
WSADATA WSAData;
int my_sock;
struct sockaddr_in sin;
char reverse_path[255];
char destinat[255];
char from[255];
char subject[255];
char to[255];
char message[1024];
char buffer[9120];
int result_connect;
char c;
char numIP[18]="62.62.156.27";
int port=25;
printf("tapez l\'adresse du correspondant : \n");
fgets(buffer,sizeof(buffer),stdin);
suppr_n(buffer);
sprintf(destinat,"RCPT TO:<%s>",buffer);
sprintf(to,"TO:<%s>",buffer);
printf("\ntapez l\'adresse de l\'expediteur\n");
fgets(buffer,sizeof(buffer),stdin);
suppr_n(buffer);
sprintf(reverse_path,"MAIL FROM:<%s>",buffer);
printf("tapez le champs from : \n");
fgets(buffer,sizeof(buffer),stdin);
suppr_n(buffer);
sprintf(from,"FROM:<%s>",buffer);
printf("\ntapez le sujet du mail : \n");
fgets(buffer,sizeof(buffer),stdin);
suppr_n(buffer);
sprintf(subject,"SUBJECT:%s",buffer);
printf("\ndestination : %s",destinat);
printf("\nreturn : %s",reverse_path);
printf("\nfrom : %s",from);
printf("\nto : %s",to);
printf("\nsujet : %s",subject);
printf("\ncorps: %s",buffer);
sprintf(buffer,"voici mon message"
"\r\n");
sprintf(message,
"EHLO <212.30.xxx.xxx>\r\n"
"%s"
"\r\n"
"%s\r\n"
"DATA \r\n"
"%s\r\n"//to
"%s\r\n"//from
"%s\r\n"//sujet
"\r\n"//separation entete corps
"%s\r\n"//corps du message
".\r\n"//indicateur de fin transaction smtp
"QUIT\r\n"
,reverse_path,destinat,to,from,subject,buffer);
printf("\n\n\n%s\n\n\n",message);
WSAStartup(MAKEWORD(2,0), &WSAData);
sin.sin_addr.s_addr = inet_addr(numIP);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
my_sock = socket(AF_INET,SOCK_STREAM,0);
printf("connexion au port %d...\n",port);
result_connect=connect(my_sock,(SOCKADDR*)&sin,sizeof(sin));
if(result_connect==0)
{
printf("connexion reussie au port %d \n\n",port);
send(my_sock,message ,sizeof(message)-1, 0);
while((recv(my_sock, &c, 1, 0))==1)
{
putchar(c);
}
closesocket(my_sock);
printf("connexion fermee\n");
}
else
printf("erreur de connexion\n");
WSACleanup();
system("pause");
return 0;
} |
Partager