SMTP Client Program

From Web (09.06.1997)

Table of Contents

1. A Visual C++ Project

Create a Project (Application) in Visual C++ (we have used MSVC 4.0)

Files in the Project:

  • smtp.cpp
  • wsock32.lib

2. smtp.cpp

#include <windows.h>
#include <winsock.h>
#include <stdio.h>

void abc(char *p)
{
  FILE *fp=fopen("z.txt","a+");
  fprintf(fp,"%s\n",p);
  fclose(fp);
}

struct sockaddr_in A;
WSADATA W;
SOCKET S;
char aa[100];
int i;
struct hostent *H;
char R[10000];

int _stdcall WinMain(HINSTANCE ii, HINSTANCE j, char *k, int l)
{
  WSAStartup (0x101, &amp;W);
  S = socket(AF_INET, SOCK_STREAM,0);
  A.sin_family=AF_INET;
  A.sin_port = htons(25);
  H=gethostbyname("giasbm01.vsnl.net.in");
  A.sin_addr.s_addr=*((unsigned long *) H->h_addr);
  i=connect(S,(struct sockaddr *) &amp;A,sizeof(A));
  sprintf(aa,"connect %d",i);
  abc(aa);
  strset(aa,' ');
  i=recv(S,R,10000,0);
  sprintf(aa,"recv %d R %s",i,R);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"HELO vijay.com\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  i=recv(S,R,10000,0);
  sprintf(aa,"recv %d R %s",i,R);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"MAIL FROM:<vijay1@giasbm01.vsnl.net.in>\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  i=recv(S,R,10000,0);
  sprintf(aa,"recv %d R %s",i,R);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"RCPT  TO:<ravi@giasbm01.vsnl.net.in>\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  i=recv(S,R,10000,0);
  sprintf(aa,"recv %d R %s",i,R);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"DATA\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  i=recv(S,R,10000,0);
  sprintf(aa,"recv %d R %s",i,R);
  abc(aa);
  strcpy(R,"To: aaa.com\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"FROM: vijay1@giasbm01.vsnl.net.in\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"DATE: 10 Jan 95 13:24 PST\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"MESSAGE_ID: <123@e.com>\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"Hello\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"How are you\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  strcpy(R,".\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  i=recv(S,R,10000,0);
  sprintf(aa,"recv %d R %s",i,R);
  abc(aa);
  strset(aa,' ');
  strcpy(R,"QUIT\r\n");
  i=send(S,R,strlen(R),0);
  sprintf(aa,"send %d ",i);
  abc(aa);
  strset(aa,' ');
  i=recv(S,R,10000,0);
  sprintf(aa,"recv %d R %s",i,R);
  abc(aa);
  return 0;
}

Have any suggestions, comments, ideas, cracked code, feedback. Feel free to get in touch with us.

Move back to the Vijay Mukhi's Technology Cornucopia Page to learn more about the other new Internet Technologies.


Vijay Mukhi's Computer Institute
VMCI, B-13, Everest Building, Tardeo, Bombay 400 034, India
E-mail:vmukhi@giasbm01.vsnl.net.in Tel : 91-22-496 4335 /6/7/8/9 Fax : 91-22-307 28 59
http://www.neca.com/~vmis