title: Validating an email address
body: <p>I am trying to send an email using c# using the following code.</p>
  
  <pre><code>MailMessage mail = new MailMessage();
  mail.From = new MailAddress(fromAddress, friendlyName);
  mail.To.Add(toAddress);
  mail.CC.Add(ccAddress);
  
  //set the content
  mail.Subject = emailSubject;
  mail.Body = emailHeader + "\n" + emailBody;
  
  //send the message
  SmtpClient smtp = new SmtpClient(ServerAddress);
  smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
  mail.IsBodyHtml = true;
  smtp.Send(mail);
  </code></pre>
  
  <p>Now the "toAddress" string that my function recieves might contain a single address, or it might have many, comma delimited addresses. </p>
  
  <p>Now the problem is that, in case of multiple comma delimited addresses, one or two of them might be of the wrong email address format. </p>
  
  <p>So when I try to send an email using this code, I get the exception:</p>
  
  <p>"The specified string is not in the form required for an e-mail address."</p>
  
  <p>Is there any way to validate the comma delimited email addresses?
  I had read somewhere that the only way to validate an email address is to send an email to it, because the regular expressions to validate an email addreess can be surprisingly huge.</p>
  
  <p>Also, I have no control over the design, or on how that address string comes to my function,I can't add the email validation in the UI, so I am helpless there...</p>
  
  <p>My problem is that the email will not be delivered to <strong>ALL</strong> the addresses in the comma delimited string, even though only <strong>SOME</strong> of the addresses are of the wrong format.</p>
  
  <p>Is there any way to properly validate email addresses in .NET? Is there a way to weed out the bad email addresses and send the mail to only the good ones?</p>