Using Data to Build Better Triggered Email Campaigns

Written by Nolan Iriarte

Categories: Email DIY

3 minute read time

Most people prefer to section off transactional and marketing emails from each other, and it’s easy to understand why. When it comes to things like your domain and IP reputation, it’s important to keep your transactional messages separate from your marketing messages. 

However, in the growing world of email automation, the lines are starting to blur and data from transactional emails gets lost in translation to marketing. Transactional data should coalesce seamlessly into targeting your marketing audience.

Data has brought us a long way

Data collection has become an abundance with the multiplex of media channels potential prospects or customers connect with to interface with a business. Our personal favorite channel (no surprise) is email. Maybe more surprisingly, email tracking for transactional and marketing emails is one of the blind spots that companies still haven’t incorporated. It’s one of the many solutions customers come to Mailgun to solve.

It’s all email, am I right?

But let’s take a step back. Way back in the day (read: a couple of years ago) bulk marketing emails were still cutting it as far as conversions for most businesses. 

Times change

Today, you can’t send email like you did back in the early 2000s with email bursts left and right. Bulk marketing emails with zero personalization have fewer open rates, clicks, and higher complaints. They’re boring, and nobody is going to click on a boring, blanket marketing push. If you can’t change with the times, you’ll get left behind in the spam folder.

Email automation has come a long way. Nowadays, you can use companies like to pull different data metrics to create highly personalized triggered email campaigns. 

With more data-driven email solutions than ever before, you can take your data and create a triggered marketing campaign sequence. These sequences create highly personalized content for the recipient, making it more meaningful for them. Better content leads to more engagements, and triggered marketing campaigns are a great way to do that. 

How do you do that? 

To start, it requires a defined plan that is set in motion by behavior and contextual data collected from your customer channels. Email marketing automation services such as and Iterable are powerful platforms and enabling designing decision-based or sequenced emails through a CRM. 

The easiest way to explain a triggered email campaign, to us at least, is with an example. Let’s take an e-commerce platform (travel booking agency) and the amount of customer email touchpoints and opportunities to have insight into a particular recipient:

  • Welcome Email
  • Password Reset Email
  • Receipt Email
  • Invoice Email
  • Shipping Notification Email

With these recipient triggered emails, Mailgun tracks the email each step of the process and provides detailed meta-data for events that occur. Insights from analytics and meta-data ensue a method for customers to structure client base segmentation. 

Bringing it together with Handlebars and Email Templates  

One of the benefits of being a more developer-focused platform is that our email templates feature gives you a lot of room to store and play. One way of doing this, especially in the case of making personalized triggered emails, is by supporting Handlebars v 3.0 and Go-lang as our template engines. With these template engines, we can create a more robust email marketing messages without too much legwork. 

Continuing with our travel booking agency example, let’s imagine a scenario in which a potential prospect signed-up with an account but has not made a purchase. We recognized from behavioral data they interacted with two particular cities while browsing our websites. With this data, we can create an email that suggests these two cities as popular travel destinations.

Our initial step is to prepare a template to be sent to re-engage with the customer. The example API request will demonstrate storing a simple HTML example including Handlebars expressions with Mailgun’s Templating feature.

import requests

html = """
{{#each place}}
 <a href={{url}}>Come Visit!</a>

def store_template():
    r =
        auth=("api", "YOUR_API_KEY"),
        data={'name': 'vacation_template',
              'description': 'template description here',
              'template': html,
              'engine': 'handlebars',
              'comment': 'version comment'})
    logs = r.json()
    print logs

The example below is referencing the template we created to the Message Send API. Tracking has been enabled to capture open & click engagement by the recipient.

import requests

def send_template_message():
    r =
        auth=("api", api_key),
        data={"from": "Excited User <mailgun@YOUR_DOMAIN_NAME>",
              "to": "",
              "subject": "Hello",
              "template": "vacation_template",
  			  "o:tracking": "yes",
              "h:X-Mailgun-Variables": '{"place": [{ "city": "Tokyo", "url": ""}, { "city": "San Francisco", "url": ""}]}'})
    print r.json()


From there, the recipient will receive an email that has those two cities as places they could travel. Pretty cool, right? This is just a simple example, but you can build sophisticated newsletters, re-engagement campaigns, and even welcome emails that are tailored to your recipient.

Data + Handlebars + email templates = great emails

Personalization at first glance is a daunting task to many senders, but it doesn’t have to be that way. If you take your data and plug and play with Handlebars, your email templates will stand out against blanket email bursts. Better emails make for better engagement, and that keeps you out of the spam folder.

Should you ever run into trouble with our templates and handlebars, feel free to reach out.

Tags: | |

Modified on: July 16, 2019

Stay up-to-date with our blog & new email resources

We'll let you know when we add new email resources and blog posts. We promise not to spam you.