Created
December 5, 2015 04:51
-
-
Save njmube/8de81efacabf2bd59713 to your computer and use it in GitHub Desktop.
Sending multiple emails in parallel using SmtpClient.SendMailAsync with async and Task.WhenAll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sendEmailTasks = recipientList.Select(async recipient => | |
{ | |
var message = new MailMessage { To = { recipient }, ... }; | |
// instantiate a new client for each mail because of this: | |
// http://www.codefrenzy.net/2012/01/30/how-asynchronous-is-smtpclient-sendasync/ | |
using (var smtpClient = new SmtpClient()) | |
{ | |
await smtpClient.SendMailAsync(message); | |
} | |
}); | |
await Task.WhenAll(sendEmailTasks); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment