2016-03-15 78 views
0

當我使用ActionMailer.Net.Mvc發送郵件時出現錯誤「值不在預期範圍內」。下面是代碼。ActionMailer .net mvc給出錯誤,值不在預期範圍內

   var context = System.Web.HttpContext.Current; 

       Task.Factory.StartNew(() => 
       { 
        System.Web.HttpContext.Current = context; 
        new MailController().NewsLetter("[email protected]", objNewsModel).Deliver(); 
       }); 



    public class MailController : MailerBase 
    { 
      public EmailResult NewsLetter(string EmailAddress, NewsModel objNewsModel) 
      { 
       To.Clear(); 
       To.Add(EmailAddress); 
       BCC.Add("[email protected]"); 
       From = "[email protected]"; 
       Subject = "Latest News"; 

       return Email("NewsLetter", objNewsModel); 
    //this (return Email("NewsLetter", objNewsModel);)line giving a error 'Value does not fall within the expected range.' 
    } 
    } 

回答

0

我試着用空的自定義視圖Newsletter.txt.cshtml您的代碼,它的作品完美。嘗試使用空白視圖,也許顯示項目時出現問題。

請記住ActionMailer不會被維護。

+0

感謝您的重播Peppi。我厭倦了空的自定義視圖Newsletter.txt.cshtml或Newsletter.html.cshtml,但它給出了相同的錯誤。 還有一件事,如果我一步一步地調試代碼,然後一段時間它的工作正常。但是,如果我運行時沒有調試,那麼總是給它的錯誤(「價值不在預期範圍內」)。 –

+0

我也看到它輸出一個異常:System.Web.dll中的'System.ArgumentException',但電子郵件生成正常(我把它放在一個文件夾中)。 –

+0

你能寄給我你的工作代碼嗎? –

相關問題