Disable HTML encoding of substitution_data

时间:2016-04-25 09:35:47

标签: sparkpost

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.

1 个答案:

答案 0 :(得分:4)

您可以使用围绕变量的3个括号,在替换变量中呈现HTML而不进行转义。例如在你的传输中有这个:

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

...你在HTML邮件正文中得到这个:

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

SparkPost参考文档中有更多详细信息:https://developers.sparkpost.com/api/#/introduction/substitutions-reference/escaping-html-values