title: SMTP client with SSL connection
body: <p>I have next sample code of using SMTP client, when I am trying to send mail via mail which uses SSL I get the following: </p>
  
  <blockquote>
    <p>550 SMTP is available only with SSL or TLS connection enabled.</p>
  </blockquote>
  
  <p>How I can extend this sample to implement SSL,, for example to send e-mail via gmail, etc... I prefer socket coding and no external library:</p>
  
  <pre><code>int main()
  {
    if (FAILED (WSAStartup (MAKEWORD( 1,1 ), &amp;ws))) 
    { 
      printf("Error in WSAStartup(...)\n");
      return 1; }
  
    // creating socket
    s = socket (AF_INET, SOCK_STREAM, 0);
    if (s == INVALID_SOCKET) 
    { 
      printf("Error in socket(...)\n");
      return 1;  }
  
    //get server address
    d_addr = gethostbyname ("smtp.mail.ru");
    if (d_addr==NULL)
    {
      printf("Error in gethostbyname(...)\n");
      return 1;  };
  
    // fill address parameters
    addr.sin_family = AF_INET; 
    addr.sin_addr.s_addr = *((unsigned long *) d_addr-&gt;h_addr);
    addr.sin_port = htons (25);
  
    // connecting...
    if (SOCKET_ERROR == (connect (s, (sockaddr *) &amp;addr,
                         sizeof (addr)))) 
    { 
      printf("Error in connect(...)\n");
      return 1; }
  
    // waiting from answer from server
    recv(s,text,sizeof(text),0);
    printf("recv - %s", text);
  
    // sy hello to server
    strcpy(text,"HELO smtp.mail.ru\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // waiting approve from server
    recv(s,text,sizeof(text),0);
    printf("recv - %s", text);
  
    // set sender
    strcpy(text,"MAIL FROM: sender@mail.ru\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // waiting for approve
    recv(s,text,sizeof(text),0);
    printf("recv - %s", text);
  
    // set receiver
    strcpy(text,"RCPT TO: receiver@mtu-net.ru\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // waiting for approve
    recv(s,text,sizeof(text),0);
    printf("recv - %s", text);
  
    // ready to start sending letter
    strcpy(text,"DATA\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // waiting for approve
    recv(s,text,sizeof(text),0);
    printf("recv - %s", text);
  
    // from whom letter
    strcpy(text,"FROM: sender@mail.ru\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // receiver
    strcpy(text,"TO: receiver@mtu-net.ru\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // letter subject
    strcpy(text,"SUBJECT: test\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // letter text
    strcpy(text,"Hi!\nIt is a message for you\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // telling that we finish
    strcpy(text,"\r\n.\r\n");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
    recv(s,text,sizeof(text),0);
    printf("recv - %s", text);
  
    // quit
    strcpy(text,"QUIT");
    send(s,text,strlen(text),0);
    printf("send - %s", text);
  
    // close socket
    closesocket(s);
  
    return 0;
  }
  </code></pre>