Hi,
this is my code:
var helper = require('sendgrid').mail;
var from_email = new helper.Email(fromEmail);
var to_email = new helper.Email(toEmail);
var subject = "subject";
var content = new helper.Content("text/html", "thanks");
var mail = new helper.Mail(from_email, subject, to_email, content);
In my case, toEmail is an array, but I get an error that says expected object but got array.
how can I send an email to several recipients using node.js, send grid templates and the helper?
thanks
Hello @otmezger,
I believe this is what you are trying to do: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html#-Sending-the-same-Email-to-Multiple-Recipients
In this case, you will want to build your own personalizations object, as the above example is for the simple case of sending a single email. We are working on making this better, please see the Mail Helper Enhancements Project and feel free to comment if you have any suggestions.
As for your current question, here is an example on how to do that: https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/helpers/mail/example.js#L15
Please let me know if you run into further issues.
Thanks!
This will probably also be resolved with #378
Most helpful comment
Hello @otmezger,
I believe this is what you are trying to do: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html#-Sending-the-same-Email-to-Multiple-Recipients
In this case, you will want to build your own personalizations object, as the above example is for the simple case of sending a single email. We are working on making this better, please see the Mail Helper Enhancements Project and feel free to comment if you have any suggestions.
As for your current question, here is an example on how to do that: https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/helpers/mail/example.js#L15
Please let me know if you run into further issues.
Thanks!