6

I'm running Postal from a service. My @Message has html. @Html.Raw is not available. When Postal runs my templated view, I get HtmlEncoded html. does anyone know how to fix this?

CurlyFro
  • 1,862
  • 4
  • 22
  • 39

2 Answers2

5

In our service, we've used:

@Raw(StringToBeEncoded)

In the html template it will complain it can not be resolved, but at runtime @Raw works fine. Its part of RazorEngine.

MattWazEre
  • 193
  • 1
  • 9
1

You can use:

@(new System.Web.HtmlString(StringToBeEncoded))

which is basically the same as does HtmlHelper.Raw(StringToBeEncoded) method under the hood. Moreover, you will not get any error in Visual Studio for the templates.

Jozef Benikovský
  • 1,121
  • 10
  • 9
  • 1
    Due to the fact Postal uses [RazorEngine](https://www.nuget.org/packages/razorengine) library internally, you can also use `@(new RazorEngine.Text.RawString(StringToBeEncoded))`, as long as you are not going to use the template outside Postal (e.g. to render directly as view in controller methods). – Jozef Benikovský Oct 24 '18 at 10:51
  • When sending an email with `Postal.EmailService.Send(email)`, using `HtmlString` will send an encoded version of the HTML, meaning open and closed brackets will be shown. When viewing a preview of the email with `new EmailViewResult(email)`, using `HtmlString` will result in an unencoded string. When sending an email with `Postal.EmailService.Send(email)`, using `RawString` will send an unencoded version of the HTML. When viewing a preview of the email with `new EmailViewResult(email)`, using `RawString` will result in an encoded string, meaning open and closed brackets will be shown. – Onosa Feb 24 '22 at 18:30