I can't seem to find a clear answer to this anywhere. I have a database full of email addresses that I need to fetch, then attach to a Mandrill email message in NodeJS. I have a basic message constructed and can send to one recipient. I need to attach my list of 1000 recipients to the message. Here's what I have. It was taken from an example in the Mandrill docs, then modified. Where and how do I include my list? I see that the to: property is an array, do I just add a variable there that is an array of objects, then send that off to Mandrill? Thanks for your help!
var message = {
"html": html,
"subject": "Subject",
"from_email": "recipient@gmail.com",
"from_name": "recipient",
"to": [{
"email": "recipient@gmail.com",
"name": "Recipient Name",
"type": "to"
},
{
"email": "recipient@gmail.com",
"name": "Pickle McGillicuddy",
"type": "to"
}],
"headers": {
"Reply-To": "recipient@gmail.com"
},
"important": false,
"track_opens": null,
"track_clicks": null,
"auto_text": null,
"auto_html": null,
"inline_css": null,
"url_strip_qs": null,
"preserve_recipients": null,
"view_content_link": null,
"bcc_address": "recipient@gmail.com",
"tracking_domain": null,
"signing_domain": null,
"return_path_domain": null,
"merge": true,
"global_merge_vars": [{
"name": "merge1",
"content": "merge1 content"
}],
"merge_vars": [{
"rcpt": "recipient@gmail.com",
"vars": [{
"name": "merge2",
"content": "merge2 content"
}]
}],
"tags": [
"password-resets"
]
};
Just add each email address to the to array in message. I think you're looking for something along these lines:
var message = { ... };
var emailAddresses = ... // get from database
for (var i in emailAddresses) {
message.to.push({
email: emailAddresses[i],
type: 'to'
});
}