andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 169 forks source link

RazorEngine.Templating.TemplateCompilationException #157

Open Adam-78 opened 8 years ago

Adam-78 commented 8 years ago

I'm trying to use ASP MVC Postal in a background job to send emails as follows:

`public void CommentCreated(Comment comment, ApplicationUser user)
{
    var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
    var engines = new ViewEngineCollection();
    engines.Add(new FileSystemRazorViewEngine(viewsPath));

    var emailService = new Postal.EmailService(engines);

    var email = new CommentCreatedEmail
    {
        To = user.Email,
        From = ConfigurationManager.AppSettings["SmtpEMailFrom"],
        Subject = "Comment Created"
        Comment = comment,
        User = user

    };

    emailService.Send(email);

}`

But I'm getting the following error:

`Exception thrown: 'RazorEngine.Templating.TemplateCompilationException' in RazorEngine.dll
 Exception thrown: 'System.Web.HttpCompileException' in System.Web.dll`

My view is as follows:

 `@model MyApp.Models.CommentCreatedEmail
 To: @Model.To
 From: @Model.From
 Subject: @Model.Subject

 <p>
   <a href="@Url.Action("Details", "Comment", new { id = @Model.Comment.Id }, "http")">@Url.Action("Details", "Comment", new { id = @Model.Comment.Id }, "http")</a>`

Any ideas?