在mvc3中使用mvcmailer

时间:2011-10-13 12:50:08

标签: asp.net-mvc-3 mvcmailer

我正在尝试在我的mvc网络应用中使用mvcmailer。当我在虚拟项目中使用它并继续维基中所述的步骤时,它工作正常,我能够发送电子邮件。

但是当我尝试将其集成到我的网络应用程序中时,它在“PopulateBody(mailMessage,viewName:”Welcome“)中给出错误;”说它无法找到_Layout.text。 _Layout.text.cshtml和_Layout.cshtml与Welcome.cshtml一起存在于Usermailer文件夹中。

用户邮件代码

public class UserMailer : MailerBase, IUserMailer     
    {
        public UserMailer():
            base()
        {
            MasterName="_Layout";
        }
public virtual MailMessage Welcome(string email, string validationUrl)
        {
            var mailMessage = new MailMessage{Subject = "Welcome to GiftSocial"};

            mailMessage.To.Add(email);
            ViewBag.Validationkey = validationUrl;
            PopulateBody(mailMessage, viewName: "Welcome");

            return mailMessage;
        } 
}

控制器代码

UserMailer.Welcome(电子邮件:model.Email,validationUrl:validationUrl).Send();

复制的异常详情:

System.Web.HttpException was unhandled by user code
  Message=The layout page "_Layout.text" could not be found at the following path: "~/Views/UserMailer/_Layout.text".
  Source=Mvc.Mailer
  ErrorCode=-2147467259
  WebEventCode=0
  StackTrace:
       at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName)
       at Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName)
       at Mvc.Mailer.MailerBase.PopulateTextBody(MailMessage mailMessage, String viewName, String masterName)
       at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary`2 linkedResources)
       at MvcGiftSocial.Mailers.UserMailer.Welcome(String email, String validationUrl) 
       at MvcGiftSocial.Controllers.AccountController.Register(RegisterViewModel viewmodel, String returnUrl) in C:\Users\ASUS\Documents\Visual Studio 2010\Projects\GiftSocialAzureNew\MvcGiftSocial\Controllers\AccountController.cs:line 86
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: 

如果有人能告诉我我做错了什么,我真诚地感激。

由于 ARNAB

1 个答案:

答案 0 :(得分:0)

错误几乎是不言自明的。找不到所需的视图。 您似乎正在尝试发送文本/纯文本邮件。因此,MvcMailer正在寻找这样的观点。

请参阅:https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide#wiki-send-multi-part-emails