【问题标题】:International characters stripped when set via global_merge_vars通过 global_merge_vars 设置时去除国际字符
【发布时间】:2015-03-03 09:34:02
【问题描述】:

给定以下由sample-template 标识的 Mandrill 电子邮件模板:

Hi *|FIRST_NAME|*,

Here are some international characters: ąćę.

和使用 Mandrill 的 Parse SDK 执行的 sendTemplate 调用:

Mandrill.sendTemplate({
    template_name: 'sample-template',
    template_content: {},
    message: {
        subject: 'This e-mail will have some characters missing',
        to: [{
            email: 'dummy@example.com',
            type: 'to',
        }],
        global_merge_vars: [{
            name: 'FIRST_NAME',
            content: 'Jędrzej',
        }],
    },
    async: true,
}, {
    success: function(httpResponse) {},
    error: function(httpResponse) {},
});

将导致以下电子邮件发送给收件人(在电子邮件客户端中查看):

Hi Jdrzej,

Here are some international characters: ąćę.

请注意名称Jędrzej 中的国际字符ę 缺失,在第一行给出Jdrzej。当国际字符直接放在模板中时不会发生这种情况,但前提是它们是通过global_merge_vars 提供的。

对原始消息的检查显示,ąćę 字符在消息正文中正确转义:

Hi Jdrzej,

Here are some international characters: =C4=85=C4=87=C4=99.

根据电子邮件标题:

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

看起来 Mandrill API 只是在将非 ASCII 字符应用到模板之前从合并值中去除它们。

在合并标签中支持国际 (UTF-8) 字符的正确方法是什么?

【问题讨论】:

    标签: parse-platform mandrill


    【解决方案1】:

    原来这是 Parse 提供的 Mandrill Cloud Code 模块的问题。查看第一个帖子下方的 cmets:https://parse.com/questions/sometimes-getting-mandrill-you-must-specify-a-key-value-error-when-sending-email

    要解决此错误,只需直接调用 Mandrill 的 API:

    Parse.Cloud.httpRequest({
        method: 'POST',
        headers: {
            Content-Type': 'application/json; charset=utf-8',
        },
        url: 'https://mandrillapp.com/api/1.0/messages/send-template.json',
        body: {
            key: MANDRILL_API_KEY,
            template_name: 'sample-template',
            template_content: {},
            message: {
                subject: 'This e-mail will will display correctly',
                to: [{
                    email: 'dummy@example.com',
                    type: 'to',
                }],
                global_merge_vars: [{
                    name: 'FIRST_NAME',
                    content: 'Jędrzej',
                }],
            },
            async: true,
        },
        success: function(httpResponse) {},
        error: function(httpResponse) {},
    });
    

    【讨论】:

      猜你喜欢
      • 2016-04-18
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      相关资源
      最近更新 更多