【问题标题】:Can't get merge tags to work - Mandrill/Parse无法让合并标签工作 - Mandrill/Parse
【发布时间】:2015-01-11 08:24:20
【问题描述】:

这是我的 Parse Cloud Code 调用:

 Mandrill.sendTemplate({
    "template_name": "start-conversation",
    "template_content": [{
        "name": "example name",
        "content": "example content" //Those are required but they are ignored
    }],
    "message": {
        "to": [{
            "email": request.params.toUserEmail,
            "name": request.params.toUserName
        }],
        "important": true, 
        "merge": true,
        "global_merge_vars": [
            {
                "rcpt": request.params.toUserEmail,
                "vars": [
                    {
                        "name": "TOUSERNAME",
                        "content": request.params.toUserName
                    },
                    {
                        "name": "FROMUSERNAME",
                        "content": request.params.fromUserName
                    },
                    {
                        "name": "TOPICNAME",
                        "content": request.params.topicName
                    },
                     {
                        "name": "LANGUAGE",
                        "content": request.params.language
                    }
                ]
            }
        ],
    },

  "async": true
},{
  success: function(httpResponse) {
    console.log(httpResponse);
    response.success("mandrillStartConvoRequest -- success -- Email sent!");
  },
  error: function(httpResponse) {
    console.error(httpResponse);
    response.error("mandrillStartConvoRequest -- error -- Uh oh, something went wrong");
  }
});

这是<span>,带有我的 Mandrill 模板中的标签:

 <span style="line-height:20.7999992370605px">
 *|TOUSERNAME|*
 <br><br>
 *|FROMUSERNAME|* would like to start a conversation with you about *|TOPICNAME|* in *|LANGUAGE|*     </span>

邮件发送正常但没有合并 =(:

【问题讨论】:

    标签: parse-platform mandrill


    【解决方案1】:

    据我所知,内置的 Mandrill.sendTemplate 方法不起作用。 所以你应该尝试自己调用 mandrill API,只需做一个 HTTP POST

    https://parse.com/questions/send-mandrill-template-email-from-cloud-code-example-code-required

    更新: 我在我的项目中使用的是这样的,注意我使用的是 merge_vars 但你使用的是 global_merge_vars

            var params = {
              key: "xxxxxxxxxxxx",
              template_name: "$template_name",
              template_content: [],
              message: {
                to: [
                  {
                    email: email
                  }
                ],
                merge_vars : [{
                  rcpt: email,
                  vars:[
                    {
                      "name" : "from",
                      "content" : "Test"
                    }
                  ]
                }]
              },
              async: true
            };
    
            Parse.Cloud.httpRequest({
              method: "POST",
              headers: {
                "Content-Type": "application/json",
              },
              url: "https://mandrillapp.com/api/1.0/messages/send-template.json",
              body: params,
              success: function(httpResponse) {
                  response.success("email sent");
                },
              error: function(httpResponse) {
                  console.error(httpResponse);
                  response.error("Uh oh, something went wrong");
                }
            });
    

    【讨论】:

    • 试过了,它没有合并。同样的问题。
    • 实际上,这行得通!一定是我 4 分钟前看到的一封延迟的电子邮件。 ~谢谢。
    猜你喜欢
    • 2013-06-20
    • 1970-01-01
    • 2013-11-24
    • 2014-04-01
    • 2016-06-25
    • 2013-08-10
    • 2013-10-23
    • 2014-06-02
    • 2014-09-21
    相关资源
    最近更新 更多