SmtpException: Failure sending mail. ---> System.InvalidOperationException: Asynchronous operations are not allowed in this context.

问题如下 

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();

});

  

猜你喜欢

转载自www.cnblogs.com/Qbit/p/12931627.html