TXmailgunrecipient-variablestransactional

How to use Draftship with Mailgun

Mailgun stores templates with versioned drafts and resolves recipient variables at send time. Paste a Draftship export, switch %recipient.first_name% tokens in, and ship via the v3 messages API.

HTML import path
code editor
Merge syntax
%recipient.first_name%
Image hosting
external
Best for
API-first teams comfortable with their own batch sending and per-recipient variable resolution.
Watch out for
Recipient Variables only resolve in batch sends. Single-recipient API calls don't substitute %recipient.X%.

Mailgun built its product around developer-controlled batch sending: one API call per batch, per-recipient variables resolved at send. The template UI exists, but a meaningful share of Mailgun customers send fully programmatic emails without templates at all. If you've built in Draftship, the simplest path is to save your export as a template and parameterize it.

Where Mailgun accepts pasted HTML

From the dashboard: Sending → Templates → Create Template. Choose Use Plain HTML. Paste your full Draftship export. Mailgun creates a version. Activate it.

STEP 1Design inDraftshipBlock editorSTEP 2ExportOutlook-safe HTMLCmd+ESTEP 3Mailgun TemplateSending > TemplatesSTEP 4Wire %recipient.X%Per-recipient varsSTEP 5Batch send via v3APImessages endpointMailgun handoff
Draftship to Mailgun template handoff

Recipient Variables and the batch send pattern

Mailgun's killer feature: the batch send. One API call sends to up to 1000 recipients, each with personalized substitutions. Use %recipient.field_name% syntax for per-recipient values:

html
<p>Hi %recipient.first_name%,</p> <p>Your order #%recipient.order_id% has shipped.</p>

Then the API call:

bash
curl -X POST \ https://api.mailgun.net/v3/yourdomain.com/messages \ -F from='Acme <noreply@yourdomain.com>' \ -F to='alex@example.com' \ -F to='blair@example.com' \ -F subject='Order shipped' \ -F template='order-shipped' \ -F 'recipient-variables={"alex@example.com":{"first_name":"Alex","order_id":"123"},"blair@example.com":{"first_name":"Blair","order_id":"456"}}'

The recipient-variables JSON keys recipients to their per-send values. Each %recipient.X% resolves per recipient.

DraftshipMailgun
{{ first_name }}%recipient.first_name%
{{ last_name }}%recipient.last_name%
{{ email }}%recipient.email% (or %recipient_email%)
Custom field%recipient.your_field%

Template handlebars (the other option)

Mailgun also supports Handlebars inside templates as a separate substitution layer. The two systems can coexist but it gets confusing fast. Pick one:

  • Recipient Variables: per-recipient values, batch send, ad-hoc.
  • Template Handlebars: structured templates, conditionals, loops, default values, similar to SendGrid Dynamic Templates.

For Draftship handoffs, Recipient Variables are usually faster to wire because the Draftship export is already self-contained.

Image hosting

Mailgun has no built-in CDN. Use your own. Hardcode absolute URLs in Draftship before export. Mailgun doesn't proxy or rewrite image URLs.

Test send checklist

  • Use the Mailgun Templates → Test to validate template rendering against a sample payload.
  • Send a real batch of one to your inbox via the API.
  • Run the output through the size checker.
  • Confirm DKIM and SPF on your sending domain via Mailgun's domain verification.

When to use Mailgun's Routes for inbound

Tangential but useful: Mailgun's Routes can forward inbound email to your webhook. If you're building two-way email flows (reply-to-task, support inbox), pair the Draftship-built outbound with Mailgun Routes for inbound parsing.

For SPF and DKIM specifics, see SPF, DKIM, and DMARC explained.

FAQ

Frequently asked questions

What's the difference between Recipient Variables and Template Handlebars in Mailgun?
Recipient Variables are a batch-send feature that substitutes %recipient.X% per recipient at send time. Handlebars is a separate template engine for structured personalization. Recipient Variables are faster for ad-hoc sends; Handlebars is better for repeatable templates.
Can I send to more than 1000 recipients in one API call?
No. Mailgun's batch limit is 1000. For larger lists, batch in your own code. Each batch is independent for delivery and reporting.
Does Mailgun support attachments?
Yes, via multipart form upload to the messages endpoint. Total message size including attachments is 25 MB.
How do I get bounce data from Mailgun?
Subscribe to webhooks for delivered, failed, complained, and unsubscribed events. The webhook payload includes the recipient and reason. Configure under Sending > Webhooks.
Why does Mailgun's pricing skew lower than SendGrid?
Mailgun is API-first with less polished UX, and bills per email at lower headline rates. Total cost depends on volume tier and feature mix; for high-volume sends Mailgun is often cheapest.
Try it yourself

Design in Draftship. Paste into Mailgun.