Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This might help you out.</p> <pre><code> public void Send(MailAddress toAddress, string subject, string body, bool priority) { Task.Factory.StartNew(() =&gt; SendEmail(toAddress, subject, body, priority), TaskCreationOptions.LongRunning); } private void SendEmail(MailAddress toAddress, string subject, string body, bool priority) { MailAddress fromAddress = new MailAddress(WebConfigurationManager.AppSettings["SmtpFromAddress"]); string serverName = WebConfigurationManager.AppSettings["SmtpServerName"]; int port = Convert.ToInt32(WebConfigurationManager.AppSettings["SmtpPort"]); string userName = WebConfigurationManager.AppSettings["SmtpUserName"]; string password = WebConfigurationManager.AppSettings["SmtpPassword"]; var message = new MailMessage(fromAddress, toAddress); message.Subject = subject; message.Body = body; message.IsBodyHtml = true; message.HeadersEncoding = Encoding.UTF8; message.SubjectEncoding = Encoding.UTF8; message.BodyEncoding = Encoding.UTF8; if (priority) message.Priority = MailPriority.High; Thread.Sleep(1000); SmtpClient client = new SmtpClient(serverName, port); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = Convert.ToBoolean(WebConfigurationManager.AppSettings["SmtpSsl"]); client.UseDefaultCredentials = false; NetworkCredential smtpUserInfo = new NetworkCredential(userName, password); client.Credentials = smtpUserInfo; client.Send(message); client.Dispose(); message.Dispose(); } </code></pre> <p>The Thread.Sleep is there because this will send mail through so fast that many SMTP servers will report too many emails from same IP error message. Although ASP.NET handles asynchronous send mail, it will not send more than one message at a time. It waits until callback occurs before sending another email. This approach will send messages in parallel as fast as the code can call Send().</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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