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
|
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
static void init(void);
static void end(void);
char dest[120] = "RCPT To: <erreur410@hotmail.fr>";
char sender[120] = "MAIL From: <gerar@gmail.com>";
char data[1024] ="DATA :azerty";
char *serveur = "74.125.79.109";
int res = 0;
int main()
{
init();//initialisation du wsa pour windows
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);//creation du socket sockstream =tcp AFinet = ipv4
if(sock == INVALID_SOCKET)
{
perror("socket()"); //verification si il ny a pas derreur
exit(errno);
}
SOCKADDR_IN sin = { 0 };
sin.sin_addr.S_un.S_addr = inet_addr(serveur);
sin.sin_port = htons(25);//recuperation du port
sin.sin_family = AF_INET;//comment l'envoiyer
if((res = connect(sock,(struct sockaddr *) &sin, sizeof(sin))) != 0)
{
perror("connect()");
exit(errno);
}
send(sock, sender, strlen(sender),0);
send(sock, dest , strlen(dest),0);
send(sock, data, strlen(data),0);
printf("envoie terminer");
end();
printf("connection fermer");
return 0;
}
static void init(void)
{
#ifdef WIN32
WSADATA wsa;
int err = WSAStartup(MAKEWORD(2, 2), &wsa);
if(err < 0)
{
puts("Échec du lancement WSA !");
exit(EXIT_FAILURE);
}
#endif
}
static void end(void)
{
#ifdef WIN32
WSACleanup();
#endif
} |
Partager