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.
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.
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:
bashcurl -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.
| Draftship | Mailgun |
|---|---|
{{ 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.