Closed theonetheycallneo closed 7 years ago
????? Does this work with this module? I'm having a hard time to get the templates to work using SMTP headers.
Don't use the headers, use the options
parameter
var mandrill = require("node-mandrill");
mandrill(
// you might be able to use a different endpoint here though
// here's the Messages endpoint, https://mandrillapp.com/api/docs/messages.JSON.html
"/messages/send", {
message: {
to: [{
email: "you@you.you",
name: "You"
}],
from_email: "me@me.me",
from_name: "Me",
subject: "You just inherited $180M",
html: "Please send me your bank account # so I can transfer it asap",
auto_text: true,
// the merge vars are just another option
global_merge_vars: [{
"name": "var1",
"content": "Global Value 1"
}],
merge_vars: [{
"rcpt": "emailadress@domain.com",
"vars": [{
"name": "fname",
"content": "John"
}, {
"name": "lname",
"content": "Smith"
}]
}]
} // end of message{}
},
function(error, response) {
if (error) {
return console.log(JSON.stringify(error));
}
console.log(response);
});
I was using the nodemailer module instead... But your example works like a charm!
thanks!
With nodemailer and custom SMTP headers, you have to JSON.stringify your object:
'X-MC-MergeVars':
JSON.stringify({"_rcpt": "emailadress@domain.com", "fname": "John", "lname":"Smith"})
For multiple recipients:
'X-MC-MergeVars': [ JSON.stringify({"_rcpt": "emailadress@domain.com", "fname": "John", "lname":"Smith"}), JSON.stringify({"_rcpt": "emailadress2@domain.com", "fname": "James", "lname":"Smith"}) ]
I feel like manipulating the headers is a feature that is meant for using the SMTP exposure of the API -- since this module uses the HTTP+REST API, I don't think you need to use the X-MC-MergeVars
header, and should opt for setting the merge vars using the "merge_vars" parameter as @akhoury mentioned.
X-MC-MergeVars: {"_rcpt": "emailadress@domain.com", "fname": "John", "lname":"Smith"}
Reference:
http://help.mandrill.com/entries/21678522-how-do-i-use-merge-tags-to-add-dynamic-content