发送模板mandrill javascript

use*_*882 5 javascript api mandrill

我是编程新手,想通过mandrill api发送模板.发送消息可以正常工作.我需要在代码中更改哪些内容才能发送模板?在mandrill文档中,我看到我可以调用我存储在帐户中的模板

"template_name": "example template_name",
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在下面的代码中正确地集成它.

我很感激你能给予的任何帮助.为了理解最简单的目的,如果您可以告诉我代码必须如何发送模板.

function log(obj) {
$('#response').text(JSON.stringify(obj));
}

var m = new mandrill.Mandrill('API Key');


var params = { 

"message": {
    "from_email":"example@domain.com",
    "from_name": "FromExampleName",
    "to":[{"email":"recipient1@domain.com", "name": "Name of Recipient"}],
    "subject": "Mandrill API Test",
    "html": "Sending a template doesn't work."
}

};



function sendTheMail() {

m.messages.send(params, function(res) {
    log(res);
}, function(err) {
    log(err);
});
}
Run Code Online (Sandbox Code Playgroud)

use*_*882 10

它解决了.

必须像这样包含模板

var params = {
"template_name": "templatename",
"template_content": [
    {
        "name": "example name",
        "content": "example content"
    }
],

"message": {
    "from_email":"example@domain.com",
    "to":[{"email":"recipient@domain.com}],
    "subject": "Subject line",
    "text": "text in the message"
}
};
Run Code Online (Sandbox Code Playgroud)

然后像这样发送

function sendTheMail() {
// Send the email!

m.messages.sendTemplate(params, function(res) {
    log(res);
}, function(err) {
    log(err);
});
}
Run Code Online (Sandbox Code Playgroud)