2013-07-03 126 views
1

我在向多个收件人发送邮件时遇到了问题。NodeJS Sendrgrid发送电子邮件给多个收件人

我的剧本是

var SendGrid = require('sendgrid').SendGrid; 
var sendgrid = new SendGrid('<<username>>', '<<password>>');  
    sendgrid.send({ 
    to: '[email protected]', 
from: '[email protected]', 
bcc: ["[email protected]","[email protected]"], 

我有两个问题在这里

  1. 我能有收件人的数组中列出?
  2. 如何在密件抄送列表中包含收件人数组?

上述两个查询相关的解决方案将是有益的确实

感谢 Nabarun

回答

2

您可以使用收件人的数组中的tobcc领域都。

例如:

var SendGrid = require('sendgrid').SendGrid; 
var sendgrid = new SendGrid('{{sendgrid username}}', '{{sendgrid password}}');  
sendgrid.send({ 
    to: ['[email protected]', '[email protected]'], 
    from: '[email protected]', 
    bcc: ['[email protected]', '[email protected]'], 
    subject: 'This is a demonstration of SendGrid sending email to mulitple recipients.', 
    html: '<img src="http://3.bp.blogspot.com/-P6jNF5dU_UI/TTgpp3K4vSI/AAAAAAAAD2I/V4JC33e6sPM/s1600/happy2.jpg" style="width: 100%" />' 
}); 

如果这不是你和节点工作没有吐出任何错误,请检查该邮件被发送,通过登录SendGrid的网站,并在看Email Activity Log

有一件事我遇到了在测试你的代码示例是,如果你要发送的tobcc到相同的Gmail地址,Gmail将它全部合并成一个电子邮件(所以没有工作出现)。确保在测试您发送电子邮件到完全不同的帐户时。

如果你需要一些电子邮件帐户与Guerrilla Mail测试是一个用于创建临时测试帐户一个很好的选择。

1

新sendgrid-更新的NodeJS已报废之前的实现方法,因此接受的答案不会帮助你了。

所以...只是一个更新,如果任何人登陆这个线程与特定的搜索结果。

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

对于Sendgrid的v3 API,我发现他们的"kitchen sink" example有帮助。下面是它相关位:

var helper = require('sendgrid').mail 

mail = new helper.Mail() 
email = new helper.Email("[email protected]", "Example User") 
mail.setFrom(email) 

mail.setSubject("Hello World from the SendGrid Node.js Library") 

personalization = new helper.Personalization() 
email = new helper.Email("[email protected]", "Example User") 
personalization.addTo(email) 
email = new helper.Email("[email protected]", "Example User") 
personalization.addTo(email) 

// ... 

mail.addPersonalization(personalization) 
+0

[阅读更多关于Sendgrid的个性化(https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html)之后,我觉得你可以做多在一个单一的个性化。这将发送一封电子邮件,其中2人在收件人字段中,而不是每封邮件都收到2封电子邮件。 –

相关问题