Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send template mandrill javascript

I am new to programming and would like to send a template via the mandrill api. Sending a message works fine. What do I have to change in my code to send a template? In the mandrill documentation I see that I can call a template I have stored in my account with this

"template_name": "example template_name",

But I don't know how to integrate this properly in my code below.

I would appreciate any help you can give. For the purpose of understanding the easiest would be if you can show me how the code would have to look in order to send the template.

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

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


var params = { 

"message": {
    "from_email":"[email protected]",
    "from_name": "FromExampleName",
    "to":[{"email":"[email protected]", "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);
});
}
like image 724
user2413882 Avatar asked May 23 '13 14:05

user2413882


People also ask

How do I add a template to Mandrill?

Use the drag and drop template editor to make the desired template, then copy the code and paste it into the Mandrill template editor. Or connect your Mandrill and Mailchimp accounts and let Mandrill copy your templates over for you.

How do I create an email template in Mandrill?

The simplest way to create templates to send through Mandrill, is to use the Mailchimp drag and drop templates, then when your template is created, click "Save and Exit". Go to the templates list, and then in the drop down to the right of the templates menu, select "Send to Mandrill".

How do I send an email using Mandrill API?

Click on “Launch Mandrill”. Click on “Setup your sending domain” button and add your domain name. It will ask you the email associated with the domain name in order to verify it. It will send you an email, click on the link to verify your account.


1 Answers

it's solved.

The template has to be included like this

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

"message": {
    "from_email":"[email protected]",
    "to":[{"email":"[email protected]}],
    "subject": "Subject line",
    "text": "text in the message"
}
};

Then send like this

function sendTheMail() {
// Send the email!

m.messages.sendTemplate(params, function(res) {
    log(res);
}, function(err) {
    log(err);
});
}
like image 72
user2413882 Avatar answered Sep 22 '22 00:09

user2413882