Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding how SmtpClient handles retries
    text
    copied!<p>I'm working against a GoogleApps account for sending event notifications from my (mvc) web-app. Usually everything works fine. When the system is asked to send more than 75 messages or so I'm seeing replies from the SMTP server:</p> <blockquote> <p>Service not available, closing transmission channel. The server response was: 4.7.0 Try again later, closing connection. (MAIL) uf10sm1153163icb.17</p> </blockquote> <p>However, the system is auto-retrying and anything my system is asked to send eventually (by everything i can tell as this point) making it out. But given how the code generates and sends the emails I don't understand how these re-tries are handled.</p> <p>I'd like to try to slow down the transmission in hopes that whatever's causing the 'Service Not Available' condition will be placated if the submissions occur asynchronously. But from the looks of the code, it already is since i'm using a Try | catch block.</p> <p>Here's the relevant bit of my facade code:</p> <pre><code>foreach (string email in recipientEmails) { try { EmailGateway.Instance.SendEmail(email, notificationSubject, notificationMessage); } catch (Exception ex) { Logger.Instance.LogException(ex); Logger.Instance.LogMessage("ERROR! Unsent email is to: " + email ); } Logger.Instance.LogMessage("Sent " + notificationSubject + " to " + email); } </code></pre> <p>And here's the Gateway code (using System.Net.Mail;):</p> <pre><code>public virtual void SendEmail(string replyToAddress, string toEmailAddress, string subject, string body) { string destinationEmailAddress = toEmailAddress; string fromEmailAddress = "my@address.com"; bool useSSL = "true"; MailMessage message = new MailMessage(fromEmailAddress, destinationEmailAddress, subject, body); message.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.EnableSsl = useSSL; smtp.Send(message); } </code></pre> <p>So i'm catching both successes and fails into my logger table. What I don't understand is how I can see a log message for <strong>both</strong> a fail and then a success condition for the same email address. That indicates a 'retry' and, while i'm not surprised that the SmtpClient (the native .net assembly) can retry without explicit code asking it to, I don't see how my facade's code is being made to log both conditions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload