0

I would like to inject content into emails from the database. I tried to do this in the View.

To: @ViewBag.To
From: lolcats@website.com
Subject: Important Message

Static Text

@Html.Raw(MvcApplication1.Data.Email.GetBlah())
@MvcApplication1.Data.Email.GetBlah()

The GetBlah just returns this for now.

public static string GetBlah()
        {
            return "Hello, my name is @ViewBag.Name";
        }

And unsurprisingly the email sent just contains the text values and not merged.

Static Text

Hello, my name is @ViewBag.Name
Hello, my name is @ViewBag.Name

The reason I want to do this is because I have to make a publish every time I need to change content in emails plus I am going to need other languages too. So I just want the controller to decide what data to use and inject it to be merged at the time.

Is this possible with Postal? Can I create my own EmailViewRenderer and pass it along to be sent out?

Piotr Kula
  • 9,597
  • 8
  • 59
  • 85
  • 1
    Postal is irrelevant I think. The razor view engine interprets the result as a string, and does not parse any razor syntax inside. You should replace your Method with `@Html.Partial()` - but load the partial razor view dynamically (using a Virtual Path Provider). See This answer for more details: http://stackoverflow.com/questions/9703119/dynamically-produce-razor-views-at-runtime – James S Jul 14 '14 at 13:38
  • Thanks James. I think that is exactly what I need and is such a great solutions for many other things too. Fantastic. I am trying to get it to work now. – Piotr Kula Jul 14 '14 at 14:06

0 Answers0