title: Sending emails using C
body: <p>I have just started learning about socket programming and learned about winsock and achieved some progress. my question is basically: I want to send emails, what should I do?</p>
  
  <p>points to be mentioned:</p>
  
  <ol>
  <li>I learned about initializing winsock. SMTP port (25). creating and connecting to sockets successfully. What should I do now?!!! (I'm stuck here)</li>
  <li>I don't want a ready-for-work code. I wanna learn. So, any books, documentations, tutorials or articles recommendations are needed.</li>
  <li>I know that C itself knows nothing about networking, does that mean I have to download some libraries? (I am using VS2010, Windows 7)</li>
  </ol>
  
  <p>Here are the links to pages I have read so far:</p>
  
  <p>basic winsock guide: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx</a></p>
  
  <p>I have read the first 14 pages from beej guide (can't post the link, new users can only post a maximum of two hyperlinks)</p>
  
  <p>I have learned about the types ( <code>WSADATA</code>, <code>addrinfo structure</code>, <code>sockaddr</code>, <code>SOCKET</code> ) and functions ( <code>WSAStartup()</code>, <code>WSACleanup()</code>, <code>getaddrinfo()</code>, <code>Shutdown()</code>, <code>WSAGetLastError()</code>, <code>socket()</code>, ... )</p>
  
  <p>and I have just started reading this article about <code>SMTP</code> <a href="http://www.faqs.org/rfcs/rfc821.html" rel="noreferrer">http://www.faqs.org/rfcs/rfc821.html</a></p>
  
  <p>here's what I have written till now:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;WinSock2.h&gt;
  #include &lt;WS2tcpip.h&gt;
  
  #pragma comment(lib, "Ws2_32.lib") // Applications that use Winsock must be linked with the Ws2_32.lib library file.
  
  #define HTTP_PORT "80"
  #define SMTP_PORT "25"
  #define HOSTNAME_PORT "101"
  
  /*
  All ports and web services names ( which are string aliases of the ports
  
   can be found here:
   %WINDIR%\system32\drivers\etc\services
  
   */
  
  int main(void)
  {
      WSADATA wsdata;
      int iresult, retval; //iresult : instant result
      SOCKET connect_socket;
      struct addrinfo *result, *ptr, hints;
  
      iresult = WSAStartup(MAKEWORD(2, 2), &amp;wsdata);
      if(iresult != 0) printf("Initiation of Winsock succeeded.\n");
      else
      {
          printf("WinSock initialization failed..\n");
          WSACleanup();
          return 0;
      }
  
      if(LOBYTE(wsdata.wVersion) == 2 &amp;&amp; HIBYTE(wsdata.wVersion) == 2) printf("winsock.dll is found.\n");
      else
      {
          printf("Can not find the required winsock.dll file.\n");
          WSACleanup();
          return 0;
      }
  
      ZeroMemory(&amp;hints, sizeof(hints));
      hints.ai_family = AF_UNSPEC; // IPv4 or IPv6
      hints.ai_protocol = IPPROTO_TCP; // TCP connection ( full duplex )
      hints.ai_socktype = SOCK_STREAM; // Provides sequenced, reliable, two-way, connection-based byte streams
  
      connect_socket = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
      if(connect_socket == INVALID_SOCKET)
      {
          printf("Socket Creation failed..\n");
          WSACleanup();
          return 0;
      }
      else printf("Socket Creation Succeeded ..\n");
      WSACleanup();
      return 1;
  }
  </code></pre>
  
  <p>am I off course?</p>