Sendgrid-nodejs: TO as array 鈥斅爏end to several emails at the same time using the helper

Created on 13 Oct 2016  路  2Comments  路  Source: sendgrid/sendgrid-nodejs

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

question

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!

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

egges picture egges  路  3Comments

thinkingserious picture thinkingserious  路  4Comments

danielflippance picture danielflippance  路  4Comments

polkhovsky picture polkhovsky  路  3Comments

amlcodes picture amlcodes  路  4Comments