Learn how to create Mailgun templates with Tokens as well as learn How to send data to a Mailgun template
Tokens in Mailgun templates allow you to dynamically insert personalized data into your emails. Follow these steps to create a Mailgun template with tokens and use it effectively.
Step-by-Step Guide on Creating Mailgun Templates With Tokens
Step 1: Access Your Mailgun Account
- Log in to your Mailgun dashboard.
- Navigate to Sending > Templates in the sidebar.
Step 2: Create a New Template
- Click on Create Template.
- Enter a name for your template (e.g., "Welcome_Email").
- Add a version for the template (e.g., "v1").
These Links may be useful to you!
Mailgun Email Templates
Templates editor
Step 3: Add Tokens to Your Template
- Use
{{token_name}}
syntax to define placeholders for dynamic data.- eg. Hi {{ firstname }},
Welcome to our service! Your account ID is {{ account_id }}.
- eg. Hi {{ firstname }},
- Add all the required tokens you want to personalize, ensuring that their names match the keys in your JSON data.
Step 4: Save and Test the Template
- Save the template once you’re done.
- Use the Preview feature to see how the email will look with sample data.
- Send a test email to confirm the tokens render correctly.
Step 5: Send Emails Using the Template
-
In your application or integration, reference the template name when sending emails.
-
Pass a JSON object with key-value pairs matching the token names in the template.
Example JSON:
{ "firstname": "John", "account_id": "12345" }
Step 6: Debugging and Optimization
- If tokens don’t populate correctly, check:
- JSON syntax.
- Token names matching between the JSON object and the template.
- Regularly update templates to ensure they meet current campaign needs.
By following these steps, you’ll create professional, personalized Mailgun templates with tokens ready for dynamic email campaigns
When working with Mailgun templates, you'll need to send data in a JSON object. This allows Mailgun to personalize your email content based on dynamic values from your workflow. Here’s an example and a simple guide to ensure your data is formatted correctly.
Step-by-Step Guide on sending emails via Hubspot
-
Understand the JSON Mapping
The data you send to Mailgun should follow the JSON syntax. For example, if you want to pass a recipient's first name, you can use the following structure:{ "firstname": "{{ enrolled_object.firstname }}" }
- Key:
"firstname"
represents the variable name Mailgun will use in the template. - Value:
"{{ enrolled_object.firstname }}"
retrieves the first name from your workflow's data source.
- Key:
-
Copy and Paste for Accuracy
JSON syntax can be sensitive to errors like missing commas or brackets. To avoid issues, copy and paste the example above into your configuration. -
Ensure Valid JSON Syntax
- Use double quotes (
"
) around keys and values. - Verify that your JSON object starts with
{
and ends with}
. - Ensure there are no trailing commas.
- Use double quotes (
4. Test Your Configuration
After setting up the JSON object, test your workflow to confirm that Mailgun receives and applies the data correctly in your template.
Troubleshooting
-
Error Message: Invalid JSON
Double-check for syntax errors like unbalanced brackets or missing quotes. -
Data Not Appearing in the Email
Verify that the variable name in your JSON object matches the placeholders in your Mailgun template.
By following these steps, you’ll successfully send data to your Mailgun template and create personalized emails