I have an array of email addresses, like so:
var to = '[user1@gmail.com,user2@gmail.com,user3@gmail.com]';
I am passing it to a javscript script to send mail via the Mandrill api,as follows:
function log(obj) {
$('#response').text(JSON.stringify(obj));
}
// create a new instance of the Mandrill class with your API key
var m = new mandrill.Mandrill('BK0z-Ark1NAZCkc2PwbSRw');
var from_email = "user4@gmail.com";
var to = '[user1@gmail.com,user2@gmail.com,user3@gmail.com]';
// create a variable for the API call parameters
var params = {
"message": {
"from_email":from_email,
"to":[{"email":to}],
"subject": "Sending a text email from the Mandrill API",
"text": "I'm learning the Mandrill API at Codecademy, it's very difficult."
}
};
function sendTheMail() {
// Send the email!
alert('this is a mail script');
m.messages.send(params, function(res) {
log(res);
}, function(err) {
log(err);
});
}
When to "to" variable is just one email address: "user1@gmail.com" there is no problem.
when I attempt to pass it as array,as above, the json response is:
[{"email":"[user1@gmail.com,user2@gmail.com,user3@gmail.com]","status":"invalid","_id":"1e25584e26c7447bb40b14dfc6b4f7fc","reject_reason":null}]
and the mail is not sent.
How can I fix this and pass the array correctly? I have tried every combination, I can think of ....