Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 1.63 KB

multiple-emails-personalizations.md

File metadata and controls

39 lines (32 loc) · 1.63 KB

Send Multiple Emails with Personalizations

Personalizations are an array of objects, each representing a separate email, that allow you to customize the metadata of each email sent within a request. The below example shows how multiple emails, each with varying metadata, are sent with personalizations.

Refer to the Sendgrid documentation for more details about personalizations.

const sgMail = require('@sendgrid/mail');
const sgHelpers = require('@sendgrid/helpers');
const Personalization = sgHelpers.classes.Personalization;

sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
    from: '[email protected]',
    subject: 'Hello world',
    text: 'Hello plain world!',
    html: '<p>Hello HTML world!</p>',
    personalizations: []
};

const personalization1 = new Personalization();
personalization1.setTo(['[email protected]', '[email protected]']);
personalization1.setCc('[email protected]');
msg.personalizations.push(personalization1);

const personalization2 = new Personalization();
personalization2.setTo(['[email protected]', '[email protected]', '[email protected]']);
personalization2.setFrom('[email protected]');
personalization2.setCc('[email protected]');
msg.personalizations.push(personalization2);

const personalization3 = new Personalization();
personalization3.setTo('[email protected]');
personalization3.setFrom('[email protected]');
personalization3.setCc('[email protected]');
personalization3.setSubject('Greetings world');
msg.personalizations.push(personalization3);

sgMail.send(msg);