1

After we switched from Mandrill to SparkPost we encountered issues when sending emails using transmission. In Mandrill merge_vars were not HTML encoded and we sometimes put HTML in them, however in SparkPost substitution_data does appear to be HTML encoded and it's messing some of our emails. Is there a global setting that allows to turn this off or at least disable it for a transmission?

Edit: I forgot to mention that we use csharp-sparkpost library, which means it might be a problem directly related to the library rather than SparkPost API and I need to investigate it further.

Edit2: I tested sending an email directly using JSON and the result was the same, so I can conclude that the HTML encoding is done by SparkPost and not by the c# library.

jahu
  • 5,427
  • 3
  • 37
  • 64

1 Answers1

5

You can render HTML in substitution variables without escaping by using 3 braces around your variables. e.g. With this in your transmission:

{
  "substitution_data": {
    "firstName": "<em>Jimbo</em>"
  },
  "content": {
    "html": "<p>Hi {{{firstName}}}</p>"
  }
}

...you get this in your HTML message body:

<p>Hi <em>Jimbo</em></p>

There are more details in the SparkPost reference docs: https://developers.sparkpost.com/api/#/introduction/substitutions-reference/escaping-html-values

Ewan Dennis
  • 396
  • 1
  • 3
  • This is really helpful. As for variable name case sensitivity, I ended writing a regex that scans through our template and replaces occurrences of substitution variable names with their correct case, so my college can keep messing them up to his heart's content. – jahu Apr 29 '16 at 12:31