Using Html in Postal with IEmailService

816 views Asked by At

I want to use Postal (http://aboutcode.net/postal/) to generate e-mails from template views. We are using it in an hybrid MVC and WebForms app.

I am trying to generate a MailMessage with Postal and then apply some legacy custom logic and send them.

I am using EmailService.CreateMailMessage and it works fine for plain html e-mails, as soon as I use @Html or @Url in my views, I get an exception like this:

Unable to compile template. The name 'Url' does not exist in the current context.

Here is some code:

dynamic email = new Email("ForgotPassword");
email.To = "..."; // removed email here
email.Subject = "Forgot your password";

var service = Factory.Get<IEmailService>();
var msg = service.CreateMailMessage(email);

Also we are using Ninject as our dependency injection framework and I defined this:

Bind<IEmailService>().ToMethod(x => new EmailService(new ViewEngineCollection {new FileSystemRazorViewEngine(HostingEnvironment.MapPath("~/Views/Emails"))}));

There's probably something I am not setting up right, but I don't know what exactly.

Thanks,

1

There are 1 answers

0
EtienneT On

This is kind of a fail for me, but I'll post an answer if anyone does the same mistake in the future. I tried to follow those instructions to run Postal outside asp.net: http://aboutcode.net/postal/outside-aspnet.html, but since I was in asp.net already, I would just use EmailService directly without initializing it with a ViewEngineCollection.