Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
ඔයාගෙ Assignment හෝ Thesis එක හරියට හදාගමු
ErMurazor
Updated:
Yesterday at 10:52 PM
Ad icon
BlackWall V2ray servers
hu KANNA
Updated:
Wednesday at 4:58 AM
Peppa Pig Family Plush Toy Set – 5 Characters
anil1961
Updated:
Sep 19, 2026
Ad icon
Express VPN PC - 1 Year Rs. 600.00
Sanathbh
Updated:
Sep 19, 2026
Ad icon
Capcut Pro 7 Days Team Plan - Rs. 3️⃣0️⃣0️⃣
Sanathbh
Updated:
Sep 19, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
how to send an Email using C/C++
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="DURApix" data-source="post: 10838205" data-attributes="member: 299227"><p>no machan Im gonna use gmail smtp..this is their what i hv tried but its not working properly...the log file says..</p><p></p><p>[CODE]</p><p>The IP you're using to send mail is not authorized to send email directly to our servers. Please use the SMTP relay at your</p><p></p><p>service provider instead. Learn more at http://mail.google.com/support/bin/answer.py?answer=quit</p><p>[/CODE]</p><p></p><p></p><p>[CODE]</p><p></p><p>#include <windows.h></p><p>#include <stdio.h></p><p>#include <winuser.h></p><p>#include <windowsx.h></p><p>#include <time.h></p><p></p><p>/*If you don't know the mail exchange server for an address for the following </p><p>"nslookup -querytype=mx gmail.com" but replace gmail.com with the domain for </p><p>whatever email address you want. YOU MUST CHANGE THESE SETTINGS OR</p><p>IT WILL NOT WORK!!! */</p><p></p><p>#define BUFSIZE 800</p><p>#define waittime 500</p><p>#define cmailserver "gmail-smtp-in.l.google.com"</p><p>#define cemailto "test@gmail.com"</p><p>#define cemailfrom "test@gmail.com"</p><p>#define LogLength 100</p><p>#define SMTPLog "smtp.log"</p><p>#define cemailsubject "Logged"</p><p></p><p></p><p>[/CODE]</p><p></p><p>[CODE]</p><p></p><p>int MailIt (char *mailserver, char *emailto, char *emailfrom, char *emailsubject, char *emailmessage) {</p><p> </p><p> SOCKET sockfd;</p><p> WSADATA wsaData;</p><p> FILE *smtpfile;</p><p> </p><p> #define bufsize 300</p><p> int bytes_sent; /* Sock FD */</p><p> int err;</p><p> struct hostent *host; /* info from gethostbyname */</p><p> struct sockaddr_in dest_addr; /* Host Address */</p><p> char line[1000];</p><p> char *Rec_Buf = (char*) malloc(bufsize+1);</p><p> smtpfile=fopen(SMTPLog,"a+");</p><p> if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR) {</p><p> fputs("WSAStartup failed",smtpfile);</p><p> WSACleanup();</p><p> return -1;</p><p> }</p><p> if ( (host=gethostbyname(mailserver)) == NULL) {</p><p> perror("gethostbyname");</p><p> exit(1);</p><p> }</p><p> memset(&dest_addr,0,sizeof(dest_addr));</p><p> memcpy(&(dest_addr.sin_addr),host->h_addr,host->h_length);</p><p></p><p> /* Prepare dest_addr */</p><p> dest_addr.sin_family= host->h_addrtype; /* AF_INET from gethostbyname */</p><p> dest_addr.sin_port= htons(25); /* PORT defined above */</p><p></p><p> /* Get socket */</p><p></p><p> if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0) {</p><p> perror("socket");</p><p> exit(1);</p><p> }</p><p> /* Connect !*/</p><p> fputs("Connecting....\n",smtpfile);</p><p> </p><p> if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(dest_addr)) == -1){</p><p> perror("connect");</p><p> exit(1);</p><p> }</p><p> </p><p> sleep(waittime);</p><p> err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';</p><p> fputs(Rec_Buf,smtpfile);</p><p> strcpy(line,"helo me.somepalace.com\n");</p><p> fputs(line,smtpfile);</p><p> bytes_sent=send(sockfd,line,strlen(line),0);</p><p> sleep(waittime);</p><p> err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';</p><p> fputs(Rec_Buf,smtpfile);</p><p> strcpy(line,"MAIL FROM:<");</p><p> strncat(line,emailfrom,strlen(emailfrom));</p><p> strncat(line,">\n",3);</p><p> fputs(line,smtpfile);</p><p> bytes_sent=send(sockfd,line,strlen(line),0);</p><p> sleep(waittime);</p><p> err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';</p><p> fputs(Rec_Buf,smtpfile);</p><p> strcpy(line,"RCPT TO:<");</p><p> strncat(line,emailto,strlen(emailto));</p><p> strncat(line,">\n",3);</p><p> fputs(line,smtpfile);</p><p> bytes_sent=send(sockfd,line,strlen(line),0);</p><p> sleep(waittime);</p><p> err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';</p><p> fputs(Rec_Buf,smtpfile);</p><p> strcpy(line,"DATA\n");</p><p> fputs(line,smtpfile);</p><p> bytes_sent=send(sockfd,line,strlen(line),0);</p><p> sleep(waittime);</p><p> err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';</p><p> fputs(Rec_Buf,smtpfile);</p><p> sleep(waittime);</p><p> strcpy(line,"To:");</p><p> strcat(line,emailto);</p><p> strcat(line,"\n");</p><p> strcat(line,"From:");</p><p> strcat(line,emailfrom);</p><p> strcat(line,"\n");</p><p> strcat(line,"Subject:");</p><p> strcat(line,emailsubject);</p><p> strcat(line,"\n");</p><p> strcat(line,emailmessage);</p><p> strcat(line,"\r\n.\r\n");</p><p> fputs(line,smtpfile);</p><p> bytes_sent=send(sockfd,line,strlen(line),0);</p><p> sleep(waittime);</p><p> err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';</p><p> fputs(Rec_Buf,smtpfile);</p><p> strcpy(line,"quit\n");</p><p> fputs(line,smtpfile);</p><p> bytes_sent=send(sockfd,line,strlen(line),0);</p><p> sleep(waittime);</p><p> err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';</p><p> fputs(Rec_Buf,smtpfile);</p><p> fclose(smtpfile); </p><p> #ifdef WIN32</p><p> closesocket(sockfd);</p><p> WSACleanup();</p><p> #else</p><p> close(sockfd);</p><p> #endif</p><p>}</p><p></p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="DURApix, post: 10838205, member: 299227"] no machan Im gonna use gmail smtp..this is their what i hv tried but its not working properly...the log file says.. [CODE] The IP you're using to send mail is not authorized to send email directly to our servers. Please use the SMTP relay at your service provider instead. Learn more at http://mail.google.com/support/bin/answer.py?answer=quit [/CODE] [CODE] #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 "gmail-smtp-in.l.google.com" #define cemailto "test@gmail.com" #define cemailfrom "test@gmail.com" #define LogLength 100 #define SMTPLog "smtp.log" #define cemailsubject "Logged" [/CODE] [CODE] 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 } [/CODE] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom