send an email in c++
Results 1 to 6 of 6

Thread: send an email in c++

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    3

    send an email in c++

    anyone there can help me please!
    I want to write a c++ code to send an email to my account. I have read and understand the code from the page: http://www.irongeek.com/i.php?page=security/keylogger
    i used a half code there
    But i have some error when I send data.

  2. #2
    Super Moderator
    Join Date
    Feb 2014
    Location
    US
    Posts
    69
    What is the error?
    Rad

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    I receiver the message in file ring.txt : it below
    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:<yyyyyyyyyyy@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: yyyyyyyyyyy@gmail.com
    Subject: Logged
    hello the world nhe

    .

    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
    i have read an solve problem but it always fail .
    this is my code i edit :
    #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 "yyyyyyyyyyy@gmail.com"
    #define LogLength 100
    #define SMTPLog "ring.txt"
    #define cemailsubject "Logged"
    char *emailmessage="hello the world nhe ";

    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");

    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
    }

  4. #4
    Super Moderator
    Join Date
    Feb 2014
    Location
    US
    Posts
    69
    It's not working because your IP address has been temporarily rate limited. To get around it would require using a different IP address.
    Rad

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    i'm testing an another computer but it has failed :
    HELO gmail-smtp-in.l.google.com
    250 mx.google.com at your service

    MAIL FROM:<xxxxx@gmail.com>
    250 2.1.0 OK cc2si10626975pbc.255 - gsmtp

    RCPT TO:<yyyyy@gmail.com>
    250 2.1.5 OK cc2si10626975pbc.255 - gsmtp

    DATA
    354 Go ahead cc2si10626975pbc.255 - gsmtp

    To: yyyyyu@gmail.com
    From: xxxxxx@gmail.com
    Subject: Logged
    hello the world nhe

    .

    550-5.7.1 [27.79.252.106 12] Our system has detected that this message is

    550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail,

    550-5.7.1 this message has been blocked. Please visit

    550-5.7.1 http://support.google.com/mail/bin/a...&answer=188131 for

    550 5quit
    550-5.7.1 [27.79.252.106 12] Our system has detected that this message is

    550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail,

    550-5.7.1 this message has been blocked. Please visit



    550-5.7.1 http://support.google.com/mail/bin/a...&answer=188131 for

    550 5


    im sure that evering i do is right i'm using smtp and port 25 .the text to send is plain text don't need to encode.so anyone can help me..

  6. #6

Similar Threads

  1. I cant send email with exim
    By boyboy400 in forum Newbie Security Questions
    Replies: 4
    Last Post: November 21st, 2008, 12:19 AM
  2. send wrong email
    By Penguin in forum AntiOnline's General Chit Chat
    Replies: 4
    Last Post: December 9th, 2003, 04:53 PM
  3. Send link via email button
    By KorpDeath in forum Site Feedback/Questions/Suggestions
    Replies: 0
    Last Post: July 2nd, 2003, 10:31 PM
  4. Send Anonymous Email (newbs)
    By xXSilentEvilXx in forum AntiOnline's General Chit Chat
    Replies: 5
    Last Post: May 22nd, 2003, 07:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides