2013-01-19 66 views

回答

0

你有兩個選擇:

一)呼叫SmtpClient.Send()代替。

b)由異步控制器調用SmtpClient.SendAsync()它:

public class HomeController : AsynController 
{ 
    [HttpPost] 
    public void IndexAsync() 
    { 
     SmtpClient client = new SmtpClient(); 

     client.SendCompleted += (s,e) => 
     { 
      AsyncManager.Parameters["exception"] = e.Error; 
      AsyncManager.OutstandingOperations.Decrement(); 
     }; 

     AsyncManager.OutstandingOperations.Increment(); 

     client.Send(GetMessage()); 
    } 

    public void IndexCompleted(Exception exception) 
    { 
     if (exception != null) 
     { 
      ModelState.AddError("", "Email send failed"); 
      return View(); 
     } 
     else 
     { 
      return Redirect("Complete"); 
     } 
    } 
} 
+0

謝謝,我會研究了B)選項。 – Alexander

相關問題