Private BOOLCHECKSMTP (stringSmtpServer,intPortstringUsernamestringpassword) {TcpClient TcpClient=NewTcpClient (SmtpServer, Port); NetworkStream Stream=Tcpclient.getstream (); if(! Waitefor (Stream," -"))return false ; SendCommand (Stream,"HELO 211.152.50.xxx\r\n"); if(! Waitefor (Stream," -"))return false; SendCommand (Stream,"AUTH login\r\n"); if(! Waitefor (Stream,"334"))return false; SendCommand (Stream,base64encode (username)+"\ r \ n"); if(! Waitefor (Stream,"334"))return false; SendCommand (Stream, Base64Encode (password)+"\ r \ n"); if(! Waitefor (Stream,"235"))return false; return true; } Private BOOLWaitefor (NetworkStream Stream,stringstrcode) { intstreamsize; byte[] Readbuffer =New byte[1024x768]; Streamsize= Stream. Read (Readbuffer,0, readbuffer.length); stringreturnvalue = Encoding.Default.GetString (Readbuffer). Substring (0, streamsize); Console.WriteLine (returnvalue); returnReturnvalue.substring (0,3). Equals (Strcode); } Private voidSendCommand (NetworkStream Stream,stringstrcmd) { byte[] writebuffer; WriteBuffer=Encoding.Default.GetBytes (Strcmd); Stream. Write (WriteBuffer,0, writebuffer.length); } Private stringBase64Encode (stringstr) { byte[] barray; Barray=Encoding.Default.GetBytes (str); returnconvert.tobase64string (Barray); }
C # Connection Server verify account password