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

馋奶兔 提交于 2019-12-01 00:42:48

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.

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/.

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