dwjohnston
dwjohnston

Reputation: 11803

How do I reference and create dynamic emails with Sendgrid?

I'm at a loss with the documentation here.

I'm trying to create a basic hello world email template, with some simple email substitutions - and I can't work out the syntax.

The documentation here suggests using a -igetreplaced- syntax, and gives the following example:

<html>
  <head></head>
  <body>
    <p>Hello -name-,<br>
       Thank you for your interest in our products. I have set up an appointment to call you at -time- EST to discuss your needs in more detail. If you would like to reschedule this call, please visit the following link: `<a href="http://example.com/reschedule?id=-customerID-">reschedule</a>`

                Regards,

                -salesContact-
                -contactPhoneNumber-<br>
    </p>
  </body>
</html>

An accompanying SMTP API JSON header might look something like this:

{
  "to": [
    "[email protected]",
    "[email protected]"
  ],
  "sub": {
    "-name-": [
      "John",
      "Jane"
    ],
    "-customerID-": [
      "1234",
      "5678"
    ],
    "-salesContact-": [
      "Jared",
      "Ben"
    ],
    "-contactPhoneNumber-": [
      "555.555.5555",
      "777.777.7777"
    ],
    "-time-": [
      "3:00pm",
      "5:15pm"
    ]
  }
}

I've tried pasting these in to the template code editor, but it doesn't work.

Can someone point me to the right documentation for getting the syntax correct?

Upvotes: 0

Views: 106

Answers (1)

dwjohnston
dwjohnston

Reputation: 11803

The syntax is Handlebars.

Use it like this:

Hello {{name}} 

with data:

{
    "name": "Bob"
}

Upvotes: 1

Related Questions