title: Sending batch email in C#
body: <p><strong>EDIT</strong>  I use following code to send batch email in C#. However, when one of the recipients have invalid email address, email is not sent even to other recipients whose email address is valid and I am getting an exception:</p>
  
  <blockquote>
    <p>system.net.mail.smtpfailedrecipientsexception failed recipients</p>
  </blockquote>
  
  <p>Is there any way I can send the email to other valid recipients even if one of the email address is invalid?</p>
  
  <pre><code>public void SendMailMessage (string[] to,string message,string subject) 
  {
      MailMessage mMailMessage = new MailMessage ();
      int lenght = to.GetLength(0);
      if (lenght &gt; 1) {
          foreach (string email in to) {
              mMailMessage.Bcc.Add ( email );
          }
      }
      else {
          mMailMessage.To.Add ( to[0] );
      }
  
              mMailMessage.From = new MailAddress ("no-replay@mycompany.net");                  
              SmtpClient mSmtpClient = new SmtpClient ();
              mMailMessage.Body = message;
              mMailMessage.IsBodyHtml = true;
              mMailMessage.Priority = MailPriority.Normal;
              mMailMessage.Subject = subject;
              mSmtpClient.EnableSsl = true;                
              ServicePointManager.ServerCertificateValidationCallback = delegate(object s,X509Certificate certificate,X509Chain chain, SslPolicyErrors sslPolicyErrors) {return true;};                    
          try {  
              mSmtpClient.Send (mMailMessage);                
      }
      catch (SmtpFailedRecipientsException ex){
          for (int i = 0; i &lt; ex.InnerExceptions.Length; i++)
          {
              SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
              if (status == SmtpStatusCode.MailboxBusy ||
                  status == SmtpStatusCode.MailboxUnavailable)
              {
                  Logger.Debug("Delivery failed - retrying in 5 seconds.");
                  System.Threading.Thread.Sleep(5000);
                  //client.Send(message);
                  mSmtpClient.Send (mMailMessage);
  
              }
              else
              {
                  Logger.Debug (string.Format ("Failed to deliver message to {0},{1}", ex.InnerExceptions[i].FailedRecipient, i));
  
              }
  
          }
      }
      catch (Exception ex)
      {
          Logger.Debug (string.Format("Exception caught in RetryIfBusy(): {0}", ex.ToString() ));
      }
  
  }
  </code></pre>
  
  <p>Moreoever, before I send string email addresses to SendMailMessage method I check they are valid or not by this method:</p>
  
  <pre><code>public bool IsValidEmail(string emailaddress)
      {
          try
          {
              MailAddress m = new MailAddress(emailaddress);
              return true;
          }
          catch (FormatException)
          {
              return false;
          }
      }
  </code></pre>