通过global_merge_vars设置时剥离的国际字符

时间:2015-01-05 19:27:03

标签: parse-platform mandrill

鉴于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)字符的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

原来这是Parse提供的Mandrill Cloud Code模块的问题。查看第一篇文章下方的评论: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) {},
});