MvcMailer SendAsync blocks ASP.NET MVC request?

Does anyone know if the MVC request blocks ASP.NET MVC method MvcMailer SendAsync in SmtpClientWrapper? Looking at the MvcMailer wiki and code, I would say yes.

So, do I still need to use something like WebBackgrounder as disussed here to send mail safely and truly asynchronously in my MVC application?

I am looking for a definitive answer.

+5
source share
1 answer

After downloading MvcMailer and running my own tests, I can confirm that SendAsync blocks the ASP.NET request until it finishes.

Microsoft confirms this behavior https://connect.microsoft.com/VisualStudio/feedback/details/688210/smtpclient-sendasync-blocking-my-asp-net-mvc-request

"SendAsync () calls SynchronizationContext.OperationStarted (), which is a way to not delete the HttpContext instance (or even push the request) until the asynchronous operation completes."

Since MvcMailer simply migrates SendAsync from System.Net.Mail, it has the same limitations.

The correct way to send asynchronous email is to use something like WebBackgrounder, since then it is a completely background operation (so it doesn't matter whether you use SendAsync or Send).

To keep things simple, you can also use Ajax to send emails, but this has the disadvantage of being a client, not a server.

+5
source

All Articles