C # verify the email account through POP3 protocol

Source: Internet
Author: User
Tags getstream email account
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 );

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.