Skip to content
Docs
/
Guides
/
Transactional emails with variables

Transactional emails with variables

Personalization is the key to the success of your email marketing. With Plunk you can easily create and send emails with variables that will be replaced with data on the go.

Adding data to a contact

Before you can add data to your emails, we need to add that data to our contacts. For this we will make use of the optional data parameter when sending events.

await fetch('https://api.useplunk.com/v1', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer API_KEY",
    },
    body: JSON.stringify({
        "event": "new-project",
        "email": "hello@useplunk.com",
        "data": {
            "company": "Plunk"
        }
    }),
});

Plunk will automatically keep track of the data you add to your users, keeping it updated as events are sent. You can add as many variables to a user as you want.

Important notes

  • Variables are case sensitive.
  • Variables can not be versioned, meaning Plunk will replace the value of a variable every time it is sent a different value.

Adding a variable to your transactional email

When sending a transactional email through Plunk, you can add variables to your email's subject and body by wrapping them in double curly brackets.

await fetch('https://api.useplunk.com/v1/send', {
    method: "POST",
    headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer API_KEY",
},
    body: JSON.stringify({
        "to": "hello@useplunk.com",
        "subject": "Your new company is {{company}}",
        "body": "Hi! We are happy to announce that you have been added to {{company}}.",
    }),
});
Last updated on November 17, 2022