Static bool validateemailaccount (string server, int port, string username, string password, out string errormessage) {errormessage = ""; // create a TCP connection tcpclient _ Server = new tcpclient (server, Port); // prepare networkstream netstream = _ server. getstream (); streamreader reader = new streamreader (_ server. getstream (); If (! Reader. readline (). contains ("+ OK") {// failed errormessage = "server link failed"; return false;} string data; byte [] chardata; string CRLF = "\ r \ n"; // login data = "user" + username + CRLF; chardata = system. text. encoding. ASCII. getbytes (data); netstream. write (chardata, 0, chardata. length); If (! Reader. readline (). contains ("+ OK") {// Account Error errormessage = "Account Error"; return false;} DATA = "pass" + password + CRLF; chardata = system. text. encoding. ASCII. getbytes (data); netstream. write (chardata, 0, chardata. length); If (! Reader. Readline (). Contains ("+ OK") {// incorrect password errormessage = "Incorrect password"; return false;} return true ;}
Call
String errormessage; bool iscontains = validateemailaccount ("pop3.163.com", 110, "wise_sandy@XXX.com", "*************", out errormessage); console. writeline (iscontains? "User exists": errormessage );