Note that there are some explanatory texts on larger screens.

plurals
  1. PONot all e-mails being sent using SmtpClient in an ASP.NET MVC getting delivered. Why? How to resolve?
    text
    copied!<p>Here is the set-up:</p> <ol> <li>I have a Notifications controller that is called from task scheduler 1x/day</li> <li>The action method pulls upwards of 300 addresses, loops thru them and uses the SmtpClient class to send an individual e-mail to each recepient.</li> </ol> <p>From what I can tell the process runs fine with no exceptions ... <em>except</em> that not all e-mails are being delivered. Anyone have any ideas on what is going on and how to resolve?</p> <p>Here is the code:</p> <pre><code>foreach (var emp in division.Users) { var fromAddress = "myfromaddress"; var mailServer = "mymailserver"; var toEmail = emp.EmailAddress; var message = new MailMessage(fromAddress, toEmail) { Subject = subject, Body = "&lt;body style='font:normal 13px tahoma,arial,helvetica;'&gt;" + body + "&lt;/body&gt;", IsBodyHtml = true }; var client = new SmtpClient(mailServer); client.Send(message); } </code></pre> <p><strong>UPDATE:</strong></p> <p>Adding a pause in between sending e-mails resolves the problem. But why does this work? And is there a better way (e.g. using Async()) that would equally resolve the issue in a better way??? </p> <p>Updated code ...</p> <pre><code>foreach (var emp in division.Users) { var fromAddress = "myfromaddress"; var mailServer = "mymailserver"; var toEmail = emp.EmailAddress; var message = new MailMessage(fromAddress, toEmail) { Subject = subject, Body = "&lt;body style='font:normal 13px tahoma,arial,helvetica;'&gt;" + body + "&lt;/body&gt;", IsBodyHtml = true }; var client = new SmtpClient(mailServer); client.Send(message); Thread.Sleep(3000); // Wait 3s until sending next message } </code></pre>
 

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