Reputation: 33
I'm using nodemailer with Sendgrid (https://github.com/nodemailer/nodemailer-smtp-transport) and I want to send emails to 2000 users at a time, with different content for each. Currently I create an SMTP transport and send my mails one at a time, but I'm facing problems and I think it would be better to make only one request to send all mails.
With Sengrid SMTP API, it is possible to send mails to many users with customized content by using substitution tags. Is it possible, with nodemailer, to use those to send customized mails to every one, in a single request ? For instance, it's possible with the sendgrid node package (https://github.com/sendgrid/smtpapi-nodejs) with setSubstitutions, but I want to keep using nodemailer.
Something like:
smtp.sendMail({
from: "Me",
to: [ "[email protected]", "[email protected]" ],
subs: { "-name-": [ "you", "him" ] },
subject: "Your name",
html: "<h1>Your name is -name-</h1>"
})
It would be much appreciated :)
Upvotes: 3
Views: 425
Reputation: 9814
You should be able to do this by setting the necessary X-SMTPAPI header explicitly.
smtp.sendMail({
headers: {
'X-SMTPAPI': '{"sub": { "-name-": ["you","him"] } }'
},
from: "Me",
to: [ "[email protected]", "[email protected]" ],
subject: "Your name",
html: "<h1>Your name is -name-</h1>"
})
Upvotes: 2