Does anyone know if the MvcMailer SendAsync method in SmtpClientWrapper blocks a ASP.NET MVC Request? Looking at the MvcMailer wiki and the code I would say yes.
So I would still need to use something like WebBackgrounder as disussed here for a safe and truly asynchronous mail send in my MVC app?
I'm looking for a definitive answer thanks.
After downloading MvcMailer and running my own tests I can confirm that SendAsync does block a ASP.NET request until completion.
Microsoft confirms this behaviour https://connect.microsoft.com/VisualStudio/feedback/details/688210/smtpclient-sendasync-blocking-my-asp-net-mvc-request
"SendAsync() calls SynchronizationContext.OperationStarted(), which is a cue to not dispose of the HttpContext instance (or even progress the request) until the asynchronous operation has completed."
As MvcMailer just wraps SendAsync from System.Net.Mail it suffers from the same limitations.
The correct way to send email asynchronously is to use something like WebBackgrounder, as then it is a totally background operation (so it doesn't matter if you use SendAsync or Send).
To keep things simple you could also use Ajax to send the email, but this has the disadvantage of being a client rather than a server operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With