无法使合并标签生效 - Mandrill / Parse

时间:2014-11-14 01:42:38

标签: parse-platform mandrill

这是我的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");
  }
});

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

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

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

enter image description here

1 个答案:

答案 0 :(得分:2)

据我所知,内置的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");
            }
        });