Bonjour, j'essaye d'envoyer un mail via gmail avec une application c++.

j'ai trouver ca sur internet, ca compile et run, et m'affiche les erreurs suivantes dans le fichier texte creer:

"Connecting....
220 smtp.gmail.com ESMTP xn11sm1583557pac.38 - gsmtp

helo me.somepalace.com
250 smtp.gmail.com at your service

MAIL FROM:<name.surname@gmail.com>
530 5.7.0 Must issue a STARTTLS command first. xn11sm1583557pac.38 - gsmtp

RCPT TO:<name.surname@gmail.com>
500 command unrecognised or out of order

DATA
500 command unrecognised or out of order

To:name.surname@gmail.com
From:name.surname@gmail.com
Subject:yo
yo

.

500 command unrecognised or out of order

421 too many errors

quit
500 command unrecognised or out of order

421 too many errors

"
code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "ws2_32.lib")
#include <windows.h>
#include <stdio.h>
#include <winuser.h>
#include <windowsx.h>
#include <time.h>
 
/*If you don't know the mail exchange server for an address for the following
"nslookup -querytype=mx gmail.com" but replace gmail.com with the domain for
whatever email address you want. YOU MUST CHANGE  THESE SETTINGS OR
IT WILL NOT WORK!!! */
 
#define BUFSIZE 800
#define waittime 500
#define cmailserver "smtp.gmail.com"
#define cemailto "name.surname@gmail.com"
#define cemailfrom "name.surname@gmail.com"
#define LogLength 100
#define SMTPLog "smtp.log"
#define cemailsubject "Logged"
 
int MailIt(char *mailserver, char *emailto, char *emailfrom, char *emailsubject, char *emailmessage) {
 
	SOCKET sockfd;
	WSADATA wsaData;
	FILE *smtpfile;
 
#define bufsize 300
	int bytes_sent;   /* Sock FD */
	int err;
	struct hostent *host;   /* info from gethostbyname */
	struct sockaddr_in dest_addr;   /* Host Address */
	char line[1000];
	char *Rec_Buf = (char*)malloc(bufsize + 1);
	smtpfile = fopen(SMTPLog, "a+");
	if (WSAStartup(0x202, &wsaData) == SOCKET_ERROR) {
		fputs("WSAStartup failed", smtpfile);
		WSACleanup();
		return -1;
	}
	if ((host = gethostbyname(mailserver)) == NULL) {
		perror("gethostbyname");
		exit(1);
	}
	memset(&dest_addr, 0, sizeof(dest_addr));
	memcpy(&(dest_addr.sin_addr), host->h_addr, host->h_length);
 
	/* Prepare dest_addr */
	dest_addr.sin_family = host->h_addrtype;  /* AF_INET from gethostbyname */
	dest_addr.sin_port = htons(25); /* PORT defined above */
 
									/* Get socket */
 
	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		perror("socket");
		exit(1);
	}
	/* Connect !*/
	fputs("Connecting....\n", smtpfile);
 
	if (connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1) {
		perror("connect");
		exit(1);
	}
 
	Sleep(waittime);
	err = recv(sockfd, Rec_Buf, bufsize, 0); Rec_Buf[err] = '\0';
	fputs(Rec_Buf, smtpfile);
	strcpy(line, "helo me.somepalace.com\n");
	fputs(line, smtpfile);
	bytes_sent = send(sockfd, line, strlen(line), 0);
	Sleep(waittime);
	err = recv(sockfd, Rec_Buf, bufsize, 0); Rec_Buf[err] = '\0';
	fputs(Rec_Buf, smtpfile);
	strcpy(line, "MAIL FROM:<");
	strncat(line, emailfrom, strlen(emailfrom));
	strncat(line, ">\n", 3);
	fputs(line, smtpfile);
	bytes_sent = send(sockfd, line, strlen(line), 0);
	Sleep(waittime);
	err = recv(sockfd, Rec_Buf, bufsize, 0); Rec_Buf[err] = '\0';
	fputs(Rec_Buf, smtpfile);
	strcpy(line, "RCPT TO:<");
	strncat(line, emailto, strlen(emailto));
	strncat(line, ">\n", 3);
	fputs(line, smtpfile);
	bytes_sent = send(sockfd, line, strlen(line), 0);
	Sleep(waittime);
	err = recv(sockfd, Rec_Buf, bufsize, 0); Rec_Buf[err] = '\0';
	fputs(Rec_Buf, smtpfile);
	strcpy(line, "DATA\n");
	fputs(line, smtpfile);
	bytes_sent = send(sockfd, line, strlen(line), 0);
	Sleep(waittime);
	err = recv(sockfd, Rec_Buf, bufsize, 0); Rec_Buf[err] = '\0';
	fputs(Rec_Buf, smtpfile);
	Sleep(waittime);
	strcpy(line, "To:");
	strcat(line, emailto);
	strcat(line, "\n");
	strcat(line, "From:");
	strcat(line, emailfrom);
	strcat(line, "\n");
	strcat(line, "Subject:");
	strcat(line, emailsubject);
	strcat(line, "\n");
	strcat(line, emailmessage);
	strcat(line, "\r\n.\r\n");
	fputs(line, smtpfile);
	bytes_sent = send(sockfd, line, strlen(line), 0);
	Sleep(waittime);
	err = recv(sockfd, Rec_Buf, bufsize, 0); Rec_Buf[err] = '\0';
	fputs(Rec_Buf, smtpfile);
	strcpy(line, "quit\n");
	fputs(line, smtpfile);
	bytes_sent = send(sockfd, line, strlen(line), 0);
	Sleep(waittime);
	err = recv(sockfd, Rec_Buf, bufsize, 0); Rec_Buf[err] = '\0';
	fputs(Rec_Buf, smtpfile);
	fclose(smtpfile);
#ifdef WIN32
	closesocket(sockfd);
	WSACleanup();
#else
	close(sockfd);
#endif
}
 
 
int main()
{
	char* server = "smtp.gmail.com";
	char* to = "name.surname@gmail.com";
	char* from = "name.surname@gmail.com";
	char* subject = "yo";
	char* mail = "yo";
	MailIt(server, to, from, subject, mail);
 
	return 0;
}
je ne connais rien a la programmation reseau, help