string response; string from = null; string subject = null; int totmessages; try { mailclient = new TcpClient(hostname.Text, 110); } catch (SocketException) { status.Text = "Unable to connect to server"; return; } ns = mailclient.GetStream(); sr = new StreamReader(ns); sw = new StreamWriter(ns); response = sr.ReadLine(); sw.WriteLine("User " + username.Text); //Send username sw.Flush(); response = sr.ReadLine(); if (response.Substring(0, 3) == "-ER") { status.Text = "Unable to log into server"; return; } sw.WriteLine("Pass " + password.Text); //Send password sw.Flush(); try { response = sr.ReadLine(); } catch (IOException) { status.Text = "Unable to log into server"; return; } if (response.Substring(0, 4) == "-ERR") { status.Text = "Unable to log into server"; return; } sw.WriteLine("stat"); //Send stat command to getnumber of messages sw.Flush(); response = sr.ReadLine(); string[] nummess = response.Split(' '); totmessages = Convert.ToInt16(nummess[1]); if (totmessages > 0) { status.Text = "you have " + totmessages + " messages"; } else { status.Text = "You have no messages"; } for (int i = 1; i <= totmessages; i++) { sw.WriteLine("top " + i + " 0"); //read header of each message sw.Flush(); response = sr.ReadLine(); while (true) { response = sr.ReadLine(); if (response == ".") break; if (response.Length > 4) { if (response.Substring(0, 5) == "From:") from = response; if (response.Substring(0, 8) == "Subject:") subject = response; } } messages.Items.Add(i + " " + from + " " + subject);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)