将电子邮件发送到多个电子邮件地址

时间:2017-09-27 08:40:52

标签: node.js sendgrid

我想发送电子邮件给超过1个人,我的代码在node.js,我使用发送网格。当我用逗号分隔时,它不起作用。而且我希望电子邮件的内容采用html格式,知道html标签。

这些是我的代码

 let html = "<b>"+"Hi John and Dee! </br>Someone needs help from a 
 CultureMee Consultant!</br>" + "Name: " +name + "</br>"+ "Email: " 
 +email+  "</br>"+ "Phone: " +phone +"</br>"+"Organisation: 
"+organisation+"</b>"+ "How can you help: " +howCanWeHelp +"</br>" 
+"Good luck!</b>"
//let html ="hello"

var helper = require('sendgrid').mail;
var from_email = new helper.Email(email);
var to_email = new 
helper.Email("dee@culturemee.com,john@culturemee.com,mehrnoosh@lizard-
apps.com");
var subject = "There is a new CultureMee Consultant Application";
var content = new helper.Content('text/plain', html);
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 (error, response) {
  if (error) {
    console.log('Error response received');
  }
  console.log(response.statusCode);
  console.log(response.body);
  console.log(response.headers);
 });

1 个答案:

答案 0 :(得分:1)

要向多个用户发送电子邮件,您需要以字符串数组的形式发送电子邮件。因此,您可以使用以下内容添加电子邮件:

to: [
  {
    email: 'email1@email.com', 
  },
  {
    email: 'email2@email.com', 
  },
],

另请查看thisthis以获取详细示例。