i have a code using socket and smtp to send an email in Devc++.when i run code i got some problem .In file ring.txt the error:
Connecting....
220 mx.google.com ESMTP ib4si25594558pad.70 - gsmtp
HELO gmail-smtp-in.l.google.com
250 mx.google.com at your service
MAIL FROM:<yyyyyyyyyy@gmail.com>
250 2.1.0 OK ib4si25594558pad.70 - gsmtp
RCPT TO:<xxxxxxxxxx@gmail.com>
250 2.1.5 OK ib4si25594558pad.70 - gsmtp
DATA
354 Go ahead ib4si25594558pad.70 - gsmtp
To: xxxxxxxxxx@gmail.com
From: yyyyyyyyyy@gmail.com
Subject: Logged
hello the world
.
421-4.7.0 [27.77.210.178 15] Our system has detected an unusual rate of
421-4.7.0 unsolicited mail originating from your IP address. To protect our
421-4.7.0 users from spam, mail sent from your IP address has been temporarily
421-4.7.0 rate limited. Please visit
421-4.7.0
http://www.googlequit
.com/mail/help/bulk_mail.html to review our Bulk
421 4.7.0 Email Senders Guidelines. ib4si25594558pad.70 - gsmtp
and now this is my code :
#include <windows.h>
#include <stdio.h>
#include <winuser.h>
#include <windowsx.h>
#include <time.h>
#define BUFSIZE 800
#define waittime 500
/*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 cmailserver "gmail-smtp-in.l.google.com"
#define cemailto "xxxxxxxxxx@gmail.com"
#define cemailfrom "yyyyyyyyyy@gmail.com"
#define LogLength 100
#define SMTPLog "ring.txt"
#define cemailsubject "Logged"
char *emailmessage="hello the world ";
int main(void)
{
time_t theTime=time(0);
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(cmailserver)) == 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 gmail-smtp-in.l.google.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,cemailfrom,strlen(cemailfrom));
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,cemailto,strlen(cemailto));
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,cemailto);
strcat(line,"\n");
strcat(line,"From: ");
strcat(line,cemailfrom);
strcat(line,"\n");
/* strcpy(line,"Cc: ");
strcat(line,"xxxxxxxxxx@gmail.com");
strcat(line,"\n");
strcpy(line,"Date: ");
strcat(line,ctime(&theTime));
strcat(line,"\n");
*/
strcat(line,"Subject: ");
strcat(line,cemailsubject);
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
}
i'm very happy if anyone can help me ....