C # code to validate the regular expression of a message

Source: Internet
Author: User
Tags expression regular expression socket

Verify the correctness of the input

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 your 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 to 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.