我有一组电子邮件地址,如下所示:
var to = '[user1@gmail.com,user2@gmail.com,user3@gmail.com]';
我将它传递给 javscript 脚本以通过 Mandrill api 发送邮件,如下所示:
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);
});
}
何时“to”变量只是一个电子邮件地址:“user1@gmail.com”没有问题。
当我尝试将它作为数组传递时,如上所述,json响应是:
[{"email":"[user1@gmail.com,user2@gmail.com,user3@gmail.com]","status":"invalid","_id":"1e25584e26c7447bb40b14dfc6b4f7fc","reject_reason":null}]
并且邮件没有发送。
我该如何解决这个问题并正确传递数组?我已经尝试了每一种组合,我能想到....