C # code for verifying the regular expression of an email

Source: Internet
Author: User

Verify input correctness

Public static bool isemail (string inputemail)
{
Inputemail = nulltostring (inputemail );
String strregex = @ "^ ([a-zA-Z0-9 _ \-\.] +) @ (\ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\.) | ([a-zA-Z0-9 \-] + \.) +) ([A-Za-Z] {2, 4} | [0-9] {1, 3}) (\]?) $ ";
RegEx Re = new RegEx (strregex );
If (Re. ismatch (inputemail ))
Return (true );
Else
Return (false );
}

Verify the correctness of the email address:

String [] HOST = (address. Split (@));
String hostname = host [1];

Iphostentry iphst = DNS. Resolve (hostname );
Ipendpoint endpt = new ipendpoint (iphst. Addresslist [0], 25 );
Socket S = new socket (endpt. addressfamily, sockettype. Stream, protocoltype. TCP );
S. Connect (endpt );

// Attempting to connect
If (! Check_response (S, smtpresponse. connect_success ))
{
S. Close ();
Return false;
}

// Helo Server
Senddata (S, String. Format ("HELO {0} \ r \ n", DNS. gethostname ()));
If (! Check_response (S, smtpresponse. generic_success ))
{
S. Close ();
Return false;
}

// Identify yourself
// Servers may resolve your domain and check whether you are listed in blacklists etc.
Senddata (S, String. Format ("mail from: {0} \ r \ n", "testexample@deepak.portland.co.uk "));
If (! Check_response (S, smtpresponse. generic_success ))
{

S. Close ();
Return false;
}

// Attempt delivery (I can use VRFY, but most SMTP servers only disable it for security reasons)
Senddata (S, address );
If (! Check_response (S, smtpresponse. generic_success ))
{

S. Close ();
Return false;
}
Return (true );

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.