Author Topic: SMTP Help !  (Read 10266 times)

Offline ngochuan1st

  • Jr. Member
  • *
  • Posts: 30
SMTP Help !
« on: September 19, 2012, 02:31:57 AM »
i want to send mail via SMTP using Gmail Account, how to write it ?? (NASM or C/C++) !!!

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: SMTP Help !
« Reply #1 on: September 19, 2012, 04:00:57 AM »
1.) Read RFC 5321, "Secure programming with OpenSSL API" (Kenneth Ballard, 2012), and "Set up POP in mail clients" (Google).

2.) Implement the SMTP protocol and use your new understanding of the OpenSSL API to provide the secure connection required by Gmail.

3.) Make sure your Gmail account is configured to support external clients.

About Bryant Keller
bkeller@about.me

Offline ngochuan1st

  • Jr. Member
  • *
  • Posts: 30
Re: SMTP Help !
« Reply #2 on: September 19, 2012, 04:02:40 AM »
Oh, thanks, i'm trying...

Offline ngochuan1st

  • Jr. Member
  • *
  • Posts: 30
Re: SMTP Help !
« Reply #3 on: September 19, 2012, 04:07:23 AM »
You can give me the example with nasm or Microsoft Visual C++ 6.0 ?

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: SMTP Help !
« Reply #4 on: September 19, 2012, 04:12:22 AM »
Read those documents I linked too and give a try. Or possibly search Google for some pre-built SMTP libraries or clients and start from there. Put forth a little effort, write some code. If you have any problems at that point, then I'll be happy to help.

About Bryant Keller
bkeller@about.me

Offline ngochuan1st

  • Jr. Member
  • *
  • Posts: 30
Re: SMTP Help !
« Reply #5 on: September 19, 2012, 04:15:59 AM »
I'm using Visual C++ 6.0
This code not work...

Code: [Select]

#include <StdAfx.h>
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <conio.h>
#define snprintf _snprintf


static void sendmail_write(
                const int  sock,
                const char *str,
                const char *arg
            ) {
    char buf[4096];

    if (arg != NULL)
        snprintf(buf, sizeof(buf), str, arg);
    else
        snprintf(buf, sizeof(buf), str);

    send(sock, buf, strlen(buf), 0);
}

static int sendmail(
                const char *from,
                const char *to,
                const char *subject,
                const char *body,
                const char *hostname,
                const int   port
            ) {

    struct hostent *host;
    struct sockaddr_in saddr_in;
    int sock = 0;

    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
        return -1;
    }

    sock = socket(AF_INET, SOCK_STREAM, 0);
    host = gethostbyname(hostname);
    saddr_in.sin_family      = AF_INET;
    saddr_in.sin_port        = htons((u_short)port);
    saddr_in.sin_addr.s_addr = 0;
    memcpy((char*)&(saddr_in.sin_addr), host->h_addr, host->h_length);

    if (connect(sock, (struct sockaddr*)&saddr_in, sizeof(saddr_in)) == -1)
{
        return -2;
    }
 
    sendmail_write(sock, "HELO %s\n",       "Testname");    // greeting****************
    sendmail_write(sock, "MAIL FROM: %s\n", from);    // from
    sendmail_write(sock, "RCPT TO: %s\n",   to);      // to   
    sendmail_write(sock, "DATA\n",          NULL);    // begin data
    sendmail_write(sock, "From: %s\n",      from);
    sendmail_write(sock, "To: %s\n",        to);
    sendmail_write(sock, "Subject: %s\n",   subject);
    sendmail_write(sock, "\n",              NULL);
    sendmail_write(sock, "%s\n",            body);    // data

    sendmail_write(sock, ".\n",             NULL);    // end data
    sendmail_write(sock, "QUIT\n",          NULL);    // terminate

    closesocket(sock);//*******************************

    return 0;
}


int main(int argc, char *argv[]) {

    int ret = sendmail(
        "from@gmail.com",  // from my account
        "to@gmail.com", // to - your account
        "Test Mail!",
        "Hello",
        "smtp.gmail.com",//this is my ISP -use your own
        25
    );

    if (ret != 0)
        fprintf(stderr, "Failed to send mail (code: %i).\n", ret);
    else
        fprintf(stdout, "Mail successfully sent.\n");
getch();
    return ret;
}



Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: SMTP Help !
« Reply #6 on: September 19, 2012, 04:45:52 AM »
Again, READ the articles and then WRITE some code. Copying some random open SMTP code from the Internet isn't going to help you learn. The first link I posted explained the SMTP protocol in detail. The second link provided you with a tutorial on how to use the OpenSSL API to create a secure connection. Gmail (afaik) doesn't support open SMTP connections, you have to authenticate first. Gmail uses TLS (RFC 2246) for this authentication. This is what the OpenSSL API is for.

About Bryant Keller
bkeller@about.me

Offline ngochuan1st

  • Jr. Member
  • *
  • Posts: 30
Re: SMTP Help !
« Reply #7 on: September 19, 2012, 05:05:40 AM »
Thanks.  where are you working? i'm come from VietNam. :-)

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: SMTP Help !
« Reply #8 on: September 19, 2012, 04:02:16 PM »
Ah, i'm hooked some function with C/C++ in NT Kernel as NtOpenProcess, NtSetInformationFile etc..., but i don't know how to communication between system driver (NT Hooking same as Antivirus) and Application (C/C++).

This has absolutely nothing to do with SMTP but rather appears to be more of a thinly veiled attempt to continue on from your prior locked post.