3

Is is possible to use Actionmailer.Net.Standalone in a console application? I keep getting an error that:

Could not find any CSHTML or VBHTML views named [CRD.html.cshtml] in the path [EmailTemplates]. Ensure that you specify the format in the file name (ie: CRD.html.cshtml.txt.cshtml or CRD.html.cshtml.html.cshtml)

Code

    public class Mailer : RazorMailerBase
{
    public override string ViewPath
    {
        get { return "EmailTemplates"; }
    }

    public RazorEmailResult Processed(string f)
    {

        From = group;
        To.Add(user);
        Subject = "CRD Process Server has processed file: " + f;
        return Email("CRD.html.cshtml");
    }
}

enter image description here

Do I need to implement a RazorViewEngine somewhere since it isn't standard with a console application?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
btm86042
  • 88
  • 1
  • 7

2 Answers2

2

A little late but maybe it still helps:

Try to change

return Email("CRD.html.cshtml");

to

return Email("CRD");

The extensions are appenden automatically.

hydr
  • 408
  • 3
  • 10
  • You have the correct usage, but ActionMailer utilizes an http context that I did not have in my project. Thanks for the answer though. – btm86042 May 15 '13 at 22:29
  • The ActionMailer.Standalone is independend of any HttpContext or dependencies to ASP.NET. For me it worked in a Console Application. The only thing is that it depends on the RazorEngine nuget package, which itself depends on the Microsoft.AspNet.Razor package. But that shouldn't cause any trouble normally. – hydr May 16 '13 at 11:39
-2

There is a open source project as a general templating engine called RazorEngine

A templating engine built upon Microsoft's Razor parsing technology. The RazorEngine allows you to use Razor syntax to build robust templates.

Simply;

string template = "Hello @Model.Name! Welcome to Razor!";
string result = Razor.Parse(template, new { Name = "World" });

Also available in NuGet;

Install-Package RazorEngine

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364