如何在sendgrid v3 node.js中向多个收件人发送电子邮件 [英] How to email multiple recipients in sendgrid v3 node.js
问题描述
有人可以帮助我向sendgrid v3 + node.js中的多个收件人发送电子邮件吗?我注意到,当我在to
字段中输入多个电子邮件地址时,只有第一个电子邮件地址会收到该电子邮件.第一个后的电子邮件地址未收到该电子邮件:
Can someone help me send an email to multiple recipients in sendgrid v3 + node.js? I've noticed that when I enter several email addresses in the to
field, only the first email address receives the email. The email addresses after the first one do not receive the email:
send: function(email, callback) {
var from_email = new helper.Email(email.from);
var to_email = new helper.Email('emailUser1@gmail.com,emailUser2@gmail.com,emailUser3@gmail.com');
var subject = email.subject;
var content = email.content
var mail = new helper.Mail(from_email, subject, to_email, content);
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
var request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON(),
});
sg.API(request, function(err, res) {
console.log(res);
if(err) {
console.log('---error sending email:---');
console.log(err);
console.log(err.response.body);
callback(500);
} else {
callback(200);
}
});
}
在上面的示例中,只有emailUser1@gmail.com
收到电子邮件; emailUser2@gmail.com
和emailUser3@gmail.com
没有收到电子邮件.
In the example above, only emailUser1@gmail.com
receives the email; emailUser2@gmail.com
and emailUser3@gmail.com
do not receive the email.
有人可以帮忙吗?
提前谢谢!
推荐答案
您是否正在使用SendGrid的 Helper Library ?您将要利用个性化.
Are you using SendGrid's Helper Library? You're going to want to leverage Personalizations.
如果您希望接收者彼此见面,则应将&命名为在单个Personalization对象中填充每个收件人.如果您不想让他们看到对方,并且希望他们每个人都清楚地接收到消息,则需要为每个不同的收件人组创建一个新的Personalization对象.
If you want the recipients to see each other, you should name & populate each of the recipients within a single Personalization object. If you don't want them to see each other, and want them to each receive the message distinctly, you'll want to make a new Personalization object for each distinct recipient group.
这篇关于如何在sendgrid v3 node.js中向多个收件人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!