title: sending email using TcpClient
body: <p>I'm trying to send an email with TcpClient in c#. 
  and I dont know if that is possible or not. </p>
  
  <p>******* I know I can use the SmtpClient but this is a homework and I just have to do it with sockets ******</p>
  
  <p>I wrote this code:</p>
  
  <pre><code>TcpClient tcpclient = new TcpClient();
  
              // HOST NAME POP SERVER and gmail uses port number 995 for POP 
  
              //tcpclient.Connect("pop.gmail.com", 995);
              tcpclient.Connect("smtp.gmail.com", 465);
              // This is Secure Stream // opened the connection between client and POP Server
              System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
              // authenticate as client  
              //sslstream.AuthenticateAsClient("pop.gmail.com");
              sslstream.AuthenticateAsClient("smtp.gmail.com");
              //bool flag = sslstream.IsAuthenticated;   // check flag
              // Asssigned the writer to stream 
              System.IO.StreamWriter sw = new StreamWriter(sslstream);
              // Assigned reader to stream
              System.IO.StreamReader reader = new StreamReader(sslstream);
              // refer POP rfc command, there very few around 6-9 command
              sw.WriteLine("EHLO " + "smtp.gmail.com");
              sw.Flush();
              sw.WriteLine("AUTH LOGIN/r/n");
              sw.Flush();
              sw.WriteLine("******@gmail.com/r/n");
              sw.Flush();
              // sent to server
              sw.WriteLine("***********/r/n");
              sw.Flush();
              //// this will retrive your first email
              //sw.WriteLine("RETR 1");
              //sw.Flush();
              //// close the connection
              //sw.WriteLine("Quit ");
              //sw.Flush();
              sw.WriteLine("MAIL FROM:&lt;" + "******@gmail.com" + "&gt;\r\n");
              sw.Flush();
              sw.WriteLine("RCPT TO:&lt;" + "*******@***.com" + "&gt;\r\n");
              sw.Flush();
              sw.WriteLine("DATA\r\n");
              sw.Flush();
              sw.WriteLine("Subject: Email test\r\n");
              sw.Flush();
              sw.WriteLine("Test 1 2 3\r\n");
              sw.Flush();
              sw.WriteLine(".\r\n");
              sw.Flush();
              sw.WriteLine("QUIT\r\n");
              sw.Flush();
  
              string str = string.Empty;
              string strTemp = string.Empty;
              while ((strTemp = reader.ReadLine()) != null)
              {
                  // find the . character in line
                  if (strTemp == ".")
                  {
                      break;
                  }
                  if (strTemp.IndexOf("-ERR") != -1)
                  {
                      break;
                  }
                  str += strTemp;
              }
          }
  </code></pre>
  
  <p>the message which reader gets is: </p>
  
  <pre><code>"250-smtp.gmail.com at your service, [151.238.124.27]\r\n250-SIZE 35882577\r\n250-8BITMIME\r\n250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH\r\n250-ENHANCEDSTATUSCODES\r\n250-PIPELINING\r\n250-CHUNKING\r\n250 SMTPUTF8\r\n451 4.5.0 SMTP protocol violation, see RFC 2821 x17-v6sm5346253edx.53 - gsmtp\r\n"
  </code></pre>
  
  <p>Any idea which part is wrong so Icould send an email via TcpClient? </p>
  
  <p>So if that cannot happen, how can I send an email using sockets?</p>