Sendgrid-nodejs: Send email to multiple recipients so that everyone sees only their email in TO header

Created on 6 Jan 2017  ·  4Comments  ·  Source: sendgrid/sendgrid-nodejs

Hello,

How can I send mail individually with one API call using Web API v3 so that every recipient sees only his address in TO box? Currently, I'm sending mails using nodejs, Web API v3 and sendgrid dependency but the problem is that users get the entire list of recipients in TO box. Here is the request:

var request = sg.emptyRequest({
        method: 'POST',
        path: '/v3/mail/send',
        body: {
            personalizations: [
                {
                    to: recepientEmails,
                    substitutions: emailTemplate.substitutions
                }
            ],
            from: {
                email: '[email protected]',
                name: 'Dorotea from AWW'
            },
            template_id: emailTemplate.template_id,
            categories: emailTemplate.categories
        }
    });

I've read that with Web API v2 I would need to use x-smtp header so that email would be sent to each recipient individually here at first row in table.
https://sendgrid.com/docs/API_Reference/Web_API/mail.html

And I've read that everything from Web API v2 with SMTP can be done with Web API v3 using only one request here.
https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html

To wrap up, I want to make one API call with Web API v3 to send email to multiple addresses and want every email to have only that recipient email in TO header.

All best,
Zvonimir

help wanted question

Most helpful comment

Hi @zvone187,

I don't know if you've already figured out how to do this, but this looks like what you're trying to achieve.

You should add a different personalization for each recipient. It should translate to something like this in the code:

// This assumes every recipient gets the same substitutions. If not, just add the right substitution for each email
const personalizations = recipientEmails.map(email => ({
    to: [{ email }],
    substitutions: emailTemplate.substitutions
}));
const request = sg.emptyRequest({
    method: 'POST',
    path: '/v3/mail/send',
    body: {
        personalizations,
        from: {
            email: '[email protected]',
            name: 'Dorotea from AWW'
        },
        template_id: emailTemplate.template_id,
        categories: emailTemplate.categories
    }
});

I'm not sure what the current limit is on the amount of recipients you can send to, in one request.

All 4 comments

Hi @zvone187,

I don't know if you've already figured out how to do this, but this looks like what you're trying to achieve.

You should add a different personalization for each recipient. It should translate to something like this in the code:

// This assumes every recipient gets the same substitutions. If not, just add the right substitution for each email
const personalizations = recipientEmails.map(email => ({
    to: [{ email }],
    substitutions: emailTemplate.substitutions
}));
const request = sg.emptyRequest({
    method: 'POST',
    path: '/v3/mail/send',
    body: {
        personalizations,
        from: {
            email: '[email protected]',
            name: 'Dorotea from AWW'
        },
        template_id: emailTemplate.template_id,
        categories: emailTemplate.categories
    }
});

I'm not sure what the current limit is on the amount of recipients you can send to, in one request.

@iamtheib thanks for the response. I got an answer from Sengrid. Yes, that was exactly what needs to be done.

It works, but what about send different attachments for different recipients?
I need to send multiple emails with the same template but different personalizations and a different attachment file for each user.

@iamtheib,

Thanks for helping out! Please fill out this form and we will send you some swag :)

With Best Regards,

Elmer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

umarhussain15 picture umarhussain15  ·  3Comments

danielflippance picture danielflippance  ·  4Comments

murphman300 picture murphman300  ·  4Comments

prasoonjalan picture prasoonjalan  ·  3Comments

thinkingserious picture thinkingserious  ·  4Comments