title: Reading Mail in Windows form Using C#
body: <p>I have tried to read my email in windows form . That is it should show my first message in email inbox. First i tried using my yahoo account . Code works fine but its not showing my message . Just am getting this result : " +OK hello from popgate-0.8.0.450444 pop113.plus.mail.bf1.yahoo.com ". </p>
  
  <p>Here is my code:</p>
  
  <pre><code>using System; 
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.Configuration;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Web.UI.HtmlControls;
  using System.IO;
  using System.Net.NetworkInformation;
  using System.Net.Security;
  using System.Net.Sockets;
  
  namespace emailcheck
   {
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          try
          {
              // create an instance of TcpClient
  
              TcpClient tcpclient = new TcpClient();
  
              // HOST NAME POP SERVER and gmail uses port number 995 for POP
  
              tcpclient.Connect("pop.mail.yahoo.com", 995);
  
              // 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.mail.yahoo.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("user@yahoo.com");
  
              // sent to server
              sw.Flush(); sw.WriteLine("password");
  
              sw.Flush();
  
              // RETR 1 will retrive your first email. it will read content of your first email
  
              sw.WriteLine("RETR 1");
  
              sw.Flush();
              // close the connection
              sw.WriteLine("Quit ");
              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;
              }
  
  
              richTextBox1.Text = str;
            //  textBox1.Text ="Congratulation.. ....!!! You read your first gmail email ";
          }
  
          catch (Exception ex)
          {
              richTextBox1.Text = ex.ToString();
          }
      }
  }}
  </code></pre>
  
  <p>Can anyone tell me how to show the message ? And also how to check other domain mails like gmail,hotmail etc .,</p>