Using dynamic templates with sendgrid (node.js)

Viewed 546

I'm trying to send a viable directly in the HTML via SendGrid. However, it's returning in the email as simple HTML

my code:

const message = {
  to: email,
  from: {
    email: "christianguimaraes1996@gmail.com",
  },
  subject: "Forgot Password",
  text: "TOKEN",
  token: token,
  html: "<p> token: {{{token}}}} </p>",
}
sgMail.send(message)

return res.send()

in the email it's received like this:

token: {{{token}}}}
1 Answers

Try like this,

 const message = {
      to: event.to,
      content: {
        token: "your token"
      },
      cc: event.cc,
      bcc: event.bcc,
      templateId: 'your dynamic tempalte ID from sendgrid"
 }

Note: In your dynamic template it has to be like this Ex: Hello {{token}}

The key value from content and your template value expression should match.

Related