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);
});
}
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.
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".
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.
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);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With