mc:edit do not work in Mailchimp template with Mandrill Javascript API

心已入冬 提交于 2019-11-30 20:35:00

问题


I'm trying to send emails through the Mandrill API with Mailchimp templates. I am doing this in the cloud code with Parse.com, see here https://www.parse.com/docs/cloud_modules_guide#mandrill. The emails are sent just fine, however, the mc:edit fields are never updated. This is the only content in the template now:

<span mc:edit="ship_id">ship_id</span>

This is what my call in Javascript looks like, hope somebody sees my mistake. I'm running this in Parse.com cloud code if that makes any difference. Thanks a lot!

var Mandrill = require('mandrill');
Mandrill.initialize('api-key');

Mandrill.sendTemplate({
    template_name: "Drip campaign",
    template_content: [{
        name: "ship_id",
        content:"Test Test"

    }],

    message: {
      text: "Hi",
      subject: "You have new mail",
      from_email: "info@example.com",
      from_name: "Thomas",
      to: [
        {
          email: "answer@example.com",
          name: "Fred"
        }
      ],
      "headers": {
          "Reply-To": "answer@example.com"
      },
      "important": false,
      "track_opens": true,
      "track_clicks": true,

    },
    async: true
    },{
    success: function(httpResponse) {

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

回答1:


As far as I understand from your question that you want to send e-mail at the same time you want to dynamically edit the mail content. As you have already used, you can do it via the Mandrill API. I suggest you to use the js files which are downloadable in the link;

https://github.com/jlainog/parse-mandrill-sendTemplate

From the js file in the github account, you can dynamically edit the mail content(must be in your template) via using the tag mc:edit.

For my case working copy of code is below;

Parse.Cloud.define("sendMail", function(request, response) {
    var Mandrill = require('cloud/mandrillSend.js');

    var sentTo = //Mail address to sent
    var subject = //Mail Subject
    var fromEmail = //From email
    var fromName = //From Name
    var sentToName = //Parameters from request
    var fullName = //Full Name

    Mandrill.initialize('YOUR MANDRILL API KEY');
    Mandrill.sendTemplate({
        template_name: "MANDRIL TEMPLATE",
        template_content: [
        {
             name: "nameHeader",
             content: sentToName,
        },
         {
                name: "mail",
                content: sentTo,
        },
        ],
        "key": "YOUR MANDRILL API KEY",
        message: {
                subject: subject,
                from_email: fromEmail,
                from_name: fromName,
            to: [{
                email: sentTo,
                name: fullName
            }],
            important: true
        },
        async: false
    }, {
        success: function (httpResponse) {
            console.log(httpResponse);
            response.success("Email sent!");
        },
        error: function (httpResponse) {
            console.error(httpResponse);
            response.error("Uh oh, something went wrong");
        }
    });
});

For example, in Mandrdil Template there is a span with the id;

<span mc:edit="mail"> test@gmail.com</span>

Hope this helps. Regards.




回答2:


Ok, so there is nothing wrong with my code, but it seems like the templates are not sent properly from Mailchimp to Mandrill as adding fields such as |NAME| for merge tages or mc:edit="name" just were not populated. At least the code of the Mailchimp template is pretty weird and very nested.

For that reason, I would recommend using your own HTML here, where you enter the merge tages or mc:edits https://mandrillapp.com/templates/.



来源:https://stackoverflow.com/questions/26309382/mcedit-do-not-work-in-mailchimp-template-with-mandrill-javascript-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!