6

私はプログラミングが初めてで、mandrill API 経由でテンプレートを送信したいと考えています。メッセージの送信は正常に機能します。テンプレートを送信するには、コードで何を変更する必要がありますか? マンドリルのドキュメントでは、これを使用してアカウントに保存したテンプレートを呼び出すことができることがわかります

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

1 に答える 1

12

解決しました。

テンプレートはこのように含める必要があります

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);
});
}
于 2013-05-25T14:14:31.577 に答える