有没有人知道如何在SendGrid提供的模板引擎中使用中文字符(或任何其他特殊字符)? 我在主题,html和文本属性中插入中文字符没有问题,它们都没问题,但是当我尝试使用AddSubsitute和EnableTempalteengine时,所有结果(测试我收到的电子邮件)将是一堆奇怪的字符。
Does anyone know how to use Chinese characters (or any other special characters) in the template engine provided by SendGrid? I have no problem plugin Chinese characters in subject, html and text properties, they all turn out okay, but when I tried to use AddSubsitute and EnableTempalteengine, all the result (testing email I received) will be bunch of weird characters.
最满意答案
SendGrid模板引擎支持unicode(包括中文字符)。 但是,要使用它们,您需要在将它们发送到SendGrid之前将它们转义。 SendGrid寻找的转义格式是Javascript Unicode Escaping,因为它是一个JSON对象(例如\u4F60\u597D\u4E16\u754C )。
要使用模板引擎发送替换,您将拥有类似于以下内容的SMTP API参数 :
{ "to" : ["nick@sendgrid.com"], "sub" : { "-test-" : [ "\u4F60\u597D\u4E16\u754C" ] }, "filters": { "templates": { "settings": { "enabled": 1, "template_id": "5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f" } } } }The SendGrid Template Engine does support unicode (including Chinese characters). To use these however, you'll need to escape them prior to sending them to SendGrid. The escape format SendGrid looks for is Javascript Unicode Escaping as it's a JSON object (e.g. \u4F60\u597D\u4E16\u754C).
To send a substitution with the template engine, you would have an SMTP API parameter something like the followin:
{ "to" : ["nick@sendgrid.com"], "sub" : { "-test-" : [ "\u4F60\u597D\u4E16\u754C" ] }, "filters": { "templates": { "settings": { "enabled": 1, "template_id": "5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f" } } } }更多推荐
发布评论