首页 > 技术文章 > SmtpException: Failure sending mail. ---> System.InvalidOperationException: Asynchronous operations are not allowed in this context.

Qbit 2020-05-21 16:31 原文

问题如下 

System.Net.Mail.SmtpException: Failure sending mail. 
---> System.InvalidOperationException: Asynchronous operations are not allowed
in this context. Page starting an asynchronous operation has to
have the Async attribute set to true and an asynchronous op

 甭理他什么页面需要异步,直接把发邮件代码仍到 Task.Run() 里面执行妥妥的完事儿 :

 

Task.Run(()=> {

SendMailCodes();

});

  

 

推荐阅读