2017-09-27 334 views
0

我想發送電子郵件給超過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("[email protected],[email protected],[email protected] 
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

用於發送電子郵件到你需要發送電子郵件作爲字符串數組多個用戶。

to: [ 
    { 
    email: '[email protected]', 
    }, 
    { 
    email: '[email protected]', 
    }, 
], 

還要檢查thisthis詳細例如:所以,你可以使用像添加電子郵件。

+0

你的意思是我應該這樣寫這部分? var to_email = new helper.Email([{email:[email protected]},{email:[email protected]},{email:mehrnoosh @ lizard- apps.com}]); – Mehr

+0

是的,試試吧 –

相關問題