user1447679
user1447679

Reputation: 3270

How to allow html in template data for dynamic Sendgrid transactional template?

Maybe I'm not seeing the obvious here. I'm using this library for sending mails. And I'm also using transactional templates.

A quick code example:

var msg = new SendGridMessage {From = new EmailAddress("[email protected]")};
var personlization = new Personalization {Tos = new List<EmailAddress> {new EmailAddress("[email protected]")}};
dynamic t = new System.Dynamic.ExpandoObject();
t.firstname = "John";
t.lastname = "Doe";
t.message = "a <br/> line <br/> break";
msg.TemplateId = "abcdefg";
personlization.TemplateData = t;
msg.Personalizations = new List<Personalization> {personlization};

var response = await client.SendEmail(msg);

I can see how to add content manually, text or html by using the htmlContent prop, but in this case I'm using a transactional template.

In the example above, the email comes through html encoded instead of creating the line breaks, and I want the personalizations to be html. In addition, the template is html.

Upvotes: 6

Views: 6734

Answers (1)

Nurdism
Nurdism

Reputation: 608

The answer your looking for is here, the issue is the template you are using

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

Upvotes: 11

Related Questions