我是编程新手,想通过mandrill发送一个模板。发送消息工作正常。要发送模板,我必须在代码中进行哪些更改?在mandrill文档中,我看到我可以使用下面的代码调用我的帐户中存储的模板
"template_name": "example template_name",但我不知道如何在下面的代码中正确地集成这一点。
如果你能给我任何帮助,我将不胜感激。为了理解的目的,最简单的将是如果你可以告诉我代码将如何看起来才能发送模板。
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);
});
}发布于 2013-05-25 22:14:32
已经解决了。
模板必须像这样包含在内
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"
}
};然后像这样发送
function sendTheMail() {
// Send the email!
m.messages.sendTemplate(params, function(res) {
log(res);
}, function(err) {
log(err);
});
}https://stackoverflow.com/questions/16716006
复制相似问题