All other options from the API definition are supported (note that some settings can be used in multiple ways, see above for full details for each setting):
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: '[email protected]',
cc: '[email protected]',
bcc: ['[email protected]', '[email protected]'],
from: '[email protected]',
replyTo: '[email protected]',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: 'd-12345678901234567890123456789012',
substitutionWrappers: ['{{', '}}'],
dynamicTemplateData: {
name: 'Some One',
id: '123',
},
attachments: [
{
content: 'Some attachment content',
filename: 'some-attachment.txt',
},
],
categories: ['Transactional', 'My category'],
sendAt: 1500077141,
headers: {
'X-CustomHeader': 'Custom header value',
},
sections: {},
customArgs: {
myCustomArg: 'some string', // must be a string
},
batchId: 'sendgrid-batch-id',
asm: {
groupId: 1
},
ipPoolName: 'sendgrid-ip-pool-name',
mailSettings: {
sandboxMode: {
enable: true,
},
},
trackingSettings: {},
};
sgMail
.send(msg)
.then(() => console.log('Mail sent successfully'))
.catch(error => {
console.error(error);
if (error.response) {
console.error(error.response.body)
}
});
As per issue #288, please note that the customArgs
field must have a string value.