I have an MVC 4 application that sends out multiple emails. For example, I have an email template for submitting an order, a template for cancelling an order, etc...
I have an Email Service
with multiple methods. My controller calls the Send
method which looks like this:
public virtual void Send(List<string> recipients, string subject, string template, object data)
{
...
string html = GetContent(template, data);
...
}
The Send
method calls GetContent
, which is the method causing the problem:
private string GetContent(string template, object data)
{
string path = Path.Combine(BaseTemplatePath, string.Format("{0}{1}", template, ".html.cshtml"));
string content = File.ReadAllText(path);
return Engine.Razor.RunCompile(content, "htmlTemplate", null, data);
}
I am receiving the error:
The same key was already used for another template!
In my GetContent
method should I add a new parameter for the TemplateKey
and use that variable instead of always using htmlTemplate
? Then the new order email template
could have newOrderKey
and CancelOrderKey
for the email template being used to cancel an order?
ITemplateManager
interface and I removed theGetContent
method like you said. Does thesetup on startup
section you mentioned above go inSend()
? – Champac