title: how to send email with c++
body: <p>i am trying to send an email using c++ visual studio 2013. from a search online i found a few code samples for doing so, however i am still unable to send an email. in some code i gt an error of cant include file no such file or directory on </p>
  
  <p><code>#include sys/socket.h</code></p>
  
  <p>i also tryed boost but it just got stuck. can anyone help me?
  last code i tryed:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  #define HELO "HELO 192.168.1.1\r\n"
  #define DATA "DATA\r\n"
  #define QUIT "QUIT\r\n"
  
  //#define h_addr h_addr_list[0]
  //FILE *fin;
  int sock;
  struct sockaddr_in server;
  struct hostent *hp, *gethostbyname();
  char buf[BUFSIZ+1];
  int len;
  char *host_id="192.168.1.10";
  char *from_id="rameshgoli@domain.com";
  char *to_id="rameshgoli@domain.com";
  char *sub="testmail\r\n";
  char wkstr[100]="hello how r u\r\n";
  
  /*=====Send a string to the socket=====*/
  
  void send_socket(char *s)
  {
      write(sock,s,strlen(s));
      write(1,s,strlen(s));
      //printf("Client:%s\n",s);
  }
  
  //=====Read a string from the socket=====*/
  
  void read_socket()
  {
      len = read(sock,buf,BUFSIZ);
      write(1,buf,len);
      //printf("Server:%s\n",buf);
  }
  
  /*=====MAIN=====*/
  int main(int argc, char* argv[])
  {
  
      /*=====Create Socket=====*/
      sock = socket(AF_INET, SOCK_STREAM, 0);
      if (sock==-1)
      {  
          perror("opening stream socket");
          exit(1);
      }
      else
          cout &lt;&lt; "socket created\n";
  
      /*=====Verify host=====*/
      server.sin_family = AF_INET;
      hp = gethostbyname(host_id);
      if (hp==(struct hostent *) 0)
      {
          fprintf(stderr, "%s: unknown host\n", host_id);
          exit(2);
      }
  
      /*=====Connect to port 25 on remote host=====*/
      memcpy((char *) &amp;server.sin_addr, (char *) hp-&gt;h_addr, hp-&gt;h_length);
      server.sin_port=htons(25); /* SMTP PORT */
      if (connect(sock, (struct sockaddr *) &amp;server, sizeof server)==-1)
      {
          perror("connecting stream socket");
          exit(1);
      }
      else
          cout &lt;&lt; "Connected\n";
      /*=====Write some data then read some =====*/
      read_socket(); /* SMTP Server logon string */
      send_socket(HELO); /* introduce ourselves */
      read_socket(); /*Read reply */
      send_socket("MAIL FROM: "); 
      send_socket(from_id);
      send_socket("\r\n");
      read_socket(); /* Sender OK */
      send_socket("VRFY ");
      send_socket(from_id);
      send_socket("\r\n");
      read_socket(); // Sender OK */
      send_socket("RCPT TO: "); /*Mail to*/
      send_socket(to_id);
      send_socket("\r\n");
      read_socket(); // Recipient OK*/
      send_socket(DATA);// body to follow*/
      send_socket("Subject: ");
      send_socket(sub);
      read_socket(); // Recipient OK*/
      send_socket(wkstr);
      send_socket(".\r\n");
      read_socket(); 
      send_socket(QUIT); /* quit */
      read_socket(); // log off */
  
      //=====Close socket and finish=====*/
      close(sock);
      exit(0);
  }
  </code></pre>