Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: Send email using SendAsync (System.Net.Mail)

is there any way in MVC to get the System.Net.Mail SendAsync to work, instead of the blocking Send method?

I tried using it but hit the "Page starting an asynchronous operation has to have the Async attribute" error, which I obviously can't resolve (or can I?) because there is no ASPX page with an @Page directive where I could add the Async attribute.

Help is greatly appreciated :(

like image 405
Alex Avatar asked Oct 14 '22 15:10

Alex


1 Answers

If you're using a third party service such as gmail to send your email and relying on SendEmail or SendAsync you may want to set up your own SMTP server which will then relay onto gmail. The benefit is that SendEmail will return much faster and you may be able to forget the whole async thing.

That way if gmail rejects you for whatever reason the email will still sit in your local queue.

This is a quick and dirty way to get somewhat reliable email sending setup.

Instructions (not personally tested, but i did this years ago*) or see this for Windows 7

*of course I only remembered i did this after spending a long time converting over to async :-(

like image 83
Simon_Weaver Avatar answered Oct 18 '22 09:10

Simon_Weaver