Nabs Nabs - 20 days ago 5
Node.js Question

NodeJS Sendrgrid Issue in sending email to multiple recepients

I am having issue in sending mails to multiple recipients.

My script is

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"],


I have two questions here


  1. Can I have array of recipients in to list?

  2. How to have an array of recipients in bcc list?



Solutions related to above two queries will be indeed helpful

Thanks
Nabarun

Answer

You may use an array of recipients in both the to and bcc fields.

For example:

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://3.bp.blogspot.com/-P6jNF5dU_UI/TTgpp3K4vSI/AAAAAAAAD2I/V4JC33e6sPM/s1600/happy2.jpg" style="width: 100%" />'
});

If this isn't working for you and Node isn't spitting out any errors, check to see if the emails are being sent, by logging into SendGrid's website and looking at the Email Activity Log.

One thing I came across while testing your code sample is if you're sending the to and bcc to the same gmail address, gmail will combine it all into one email (so it appears it didn't work). Make sure when testing you're sending email to entirely different accounts.

If you need some email accounts to test with Guerrilla Mail is an excellent option for creating temporary test accounts.