title: Getting a Mailbox unavailable. Too many invalid recipients error
body: <p>Our application sends out emails using the </p>
  
  <pre><code>new SmtpClient(smtpServer).Send(message);
  </code></pre>
  
  <p>We are making sure that the smtpServer is valid, the message has To and From addresses, a subject and a body. If any of these are missing, we would log an exception before even attempting to send a message.</p>
  
  <p>But the application frequently fails with the below exception.</p>
  
  <p><strong>Email Fail: System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: Too many invalid recipients.</strong></p>
  
  <p>Now, please note that the email send functionality is not failing always. For the same "To" address, it fails, may be about half the times. So, if the application tries sending out emails 100 times, we are getting some 40+ failures with the same message.</p>
  
  <p>I have already validated that the To address and the From address exists. We are seeing this issue since last month when we shifted from Outlook to Gmail.
  Here is the code.</p>
  
  <pre><code>if (fromAddress.Length == 0)
                  fromAddress = Resources.FromAddress;
  
              if (toAddress.Length == 0) return "To Address is Required.";
  
  
              if (smtpServer.Length == 0)
                  smtpServer = Resources.SMTPServer;
  
              if (string.IsNullOrEmpty(smtpServer))
                  return "SMTP sever not specified";
  
  
              MailMessage mailMessage = new MailMessage();
  
              //set the addresses
              mailMessage.From = new MailAddress(fromAddress);
              string[] toAdds = toAddress.Split(';');
              short i = 0;
              foreach (string address in toAdds)
              {
                 if(i==0) mailMessage.To.Add(address); else  mailMessage.CC.Add(address);
                  i++;
              }
  
              if (!string.IsNullOrEmpty(bcc))
              {
                  string[] bccAddresses = bcc.Split(';');
  
                  foreach (string address in bccAddresses)
                  {
                      mailMessage.Bcc.Add(address);
                  }
              }
  
              if (!string.IsNullOrEmpty(cc))
              {
                  string[] ccAddresses = cc.Split(';');
  
                  foreach (string address in ccAddresses)
                  {
                      mailMessage.CC.Add(address);
                  }
              }
  
              if (subject.Length &gt; 0)
                  mailMessage.Subject = subject;
  
              mailMessage.Body = sBody;
              mailMessage.IsBodyHtml = true;
  
              SmtpClient emailClient = new SmtpClient(smtpServer);
              emailClient.Send(mailMessage);
  </code></pre>
  
  <p>Any directions?</p>