Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sendgrid substitutions not working

I'm just trying to set up a trial email for SendGrid, it's the first time I've used it so I'm sure this is simple, but I can't seem to get the placeholder data to replace.

I'm using NodeJS library like this:

sgMail.setApiKey(mailConfig.apiKey);

const msgConfig = {
  to: email,
  from: mailConfig.defaults.from,
  templateId: mailConfig.templates.registrationConfirmation,
  substitutions: {
    '--displayName--': original.displayName,
    '--companyName--': 'Hello world'
  }
};

console.log('Sending: ', msgConfig);

// now send the registration confirmation email.
return sgMail.send(msgConfig).then(() => {
  console.log('done.');
})
.catch((err) => {
  console.error(JSON.stringify(err));
});

And in the template there's a text block that I added using the visual editor:

Hello --displayName--

We would love to take this opportunity to welcome you to the store.

from

--companyName--

However when I run the test to send the email, it sends the mail okay, but doesn't substitute the placeholders.

What am I missing here?

like image 347
Richard G Avatar asked May 05 '26 20:05

Richard G


1 Answers

try changing 'substitutions' to 'dynamicTemplateData'. Looks like they changed the name in the new version.

how i figured it out: https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/USE_CASES.md

like image 128
JohnnyMontana Avatar answered May 08 '26 03:05

JohnnyMontana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!