gpt4 book ai didi

javascript - 发送模板山魈javascript

转载 作者:数据小太阳 更新时间:2023-10-29 05:55:20 24 4
gpt4 key购买 nike

我是编程新手,想通过 mandrill api 发送模板。发送消息工作正常。我必须更改我的代码才能发送模板吗?在 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);
});
}

最佳答案

解决了。

模板必须像这样包含

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);
});
}

关于javascript - 发送模板山魈javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16716006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com