Link to home
Start Free TrialLog in
Avatar of VBBRett
VBBRett

asked on

Valid email address?

How do you check to see if an email address is valid before you send an email to that address?  I want to write a program that validates emails before I send anything.
ASKER CERTIFIED SOLUTION
Avatar of echefjosef
echefjosef
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBBRett
VBBRett

ASKER

So if I use the following code, it will tell me if the email address is valid or not?

public bool IsValidEmail(string email)
{
  try
   {
      var  addr = new System.Net.Mail.MailAddress(email);
      // Valid address
      return true;
   }
   catch
   {
      // The address is invalid
      return false;
   }
}