title: Email using System.Net.Mail through Google Apps Timing out
body: <p>I have a ASP.NET 4.0 web application, which the HR team uses to send out surveys to employees. Since we use a Google Apps, I am trying to send these survey emails through the Google Apps Account.</p>
  
  <p>I have used the following settings to send out emails.</p>
  
  <pre><code>Host - smtp.gmail.com
  Port - 587
  EnableSsl=true
  </code></pre>
  
  <p>along with my username and password.</p>
  
  <p>This is the code for sending out emails.</p>
  
  <pre><code>using (SmtpClient smtp = new SmtpClient())
                  {
                      smtp.Timeout = 0;
                      smtp.Send(message);
                  }
  </code></pre>
  
  <p>The settings are in the web.config and are read from there.</p>
  
  <p>Now my issue..</p>
  
  <p>The hr team selects multiple users to send the survey to. They could just select 1 or maybe up to 100 at a time to send out surveys. Since each survey link has to be different, I iterate the list of users and email them. </p>
  
  <p>Now after the application send out a maximum of 12 emails, it stops sending out any more. The next email it tries to send it throws an error.</p>
  
  <pre><code>Message = The operation has timed out.
  Status Code =GeneralFailure
  Stack Trace =   at System.Net.Mail.SmtpClient.Send(MailMessage message)
     at ABC.Business.Mail.SendMail(MailMessage message, String&amp; errorMessage)
  </code></pre>
  
  <p>Then onwards if I retry again it throws an error</p>
  
  <pre><code>Message = Failure sending mail.
  Status Code =GeneralFailure
  Stack Trace =   at System.Net.Mail.SmtpClient.Send(MailMessage message)
     at ABC.Business.Mail.SendMail(MailMessage message, String&amp; errorMessage)
  </code></pre>
  
  <p>If its come to this state, the only way out is to retart IIS. If I restart IIS, it starts working fine again for the next 12 odd.</p>
  
  <p>What could be the issue? Please help.</p>