---
title: "Migrate from Mailgun to Nextmail"
description: "Move from Mailgun to Nextmail: every field mapped, a code converter for Node.js, Python, Ruby, PHP and cURL, and the webhook events side by side."
url: "https://nextmail.sh/migrate/mailgun"
---

[All migrations](https://nextmail.sh/migrate.md)

Migrate from Mailgun

# Move from Mailgun to Nextmail.

Point the Mailgun SDK at Nextmail and keep your code, or convert it to the Nextmail SDK. Domains, o: options and v: variables are mapped field by field.

[Convert your code](https://nextmail.sh/migrate/mailgun#convert) [Open mail](https://nextmail.sh/mail/inbox) [Get Started](https://nextmail.sh/signup.md)

## The same email, written both ways.

One message with a reply-to address and a tag, sent through Mailgun and then through Nextmail.

```
1import FormData from 'form-data'2import Mailgun from 'mailgun.js'3 4const mailgun = new Mailgun(FormData)5const mg = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY })6 7const result = await mg.messages.create('mg.acme.com', {8  from: 'Acme <billing@acme.com>',9  to: ['ada@example.com'],10  subject: 'Your invoice is ready',11  html: '<p>Thanks for your order.</p>',12  'h:Reply-To': 'support@acme.com',13  'o:tag': ['invoice'],14})15 16console.log(result.id)
```

```
1import { init, nextmail } from '@nextmail/sdk'2 3init({ apiKey: process.env.NEXTMAIL_API_KEY })4 5const email = await nextmail.emails.send({6  from: 'Acme <billing@acme.com>',7  to: ['ada@example.com'],8  subject: 'Your invoice is ready',9  html: '<p>Thanks for your order.</p>',10  replyTo: 'support@acme.com',11  tags: { tag: 'invoice' },12})13 14console.log(email.id)
```

## Field by field, what goes where.

Each option Mailgun takes, and its place in Nextmail.

| Mailgun | Nextmail | Notes |
| --- | --- | --- |
| `messages.create(domain, …)` | `from` | The domain of the from address decides. |
| `h:Reply-To` | `replyTo` | One address per message. |
| `h:X-*` | `headers` | One object of names and values. |
| `o:tag, v:*` | `tags` | Up to 10 key and value pairs. |
| `o:deliverytime` | `scheduledAt` | An ISO time instead of an RFC 2822 date. |
| `o:tracking-opens, o:tracking-clicks` | `tracking: { opens, clicks }` | Booleans instead of yes and no. |
| `template, t:variables` | `template: { id, props }` | Recreate the template in Nextmail first. |
| `attachment` | `attachments` | Base64 or bytes, 5 MB in total. |
| `recipient-variables` | `emails.sendBatch` | One entry per recipient, values filled in. |

Converter

## Paste your Mailgun code, get it back on Nextmail.

Pick where the code comes from and its language. Recognised keys are removed in your browser, and nothing you paste is kept.

From Mailgun

Your Nextmail code appears here

Paste a file, or load an example, then convert.

0 of 12,000 characters Recognised keys are removed before sending.

## Beyond the code, four more steps.

1. 01
   
   Add your sending domain
   
   Add it in Nextmail and publish the DNS records it lists. Sending starts once the signing record answers.
2. 02
   
   Create an API key
   
   Keys start with oe\_live\_ and carry only the scopes you give them.
3. 03
   
   Move your webhooks
   
   Create an endpoint for the events listed below and check the X-OpenEmail-Signature header on every request.
4. 04
   
   Bring the rest with one key
   
   In Migrations, choose From a provider and paste a Mailgun key. Suppressions, mailing lists, members, templates and webhooks come across, and domains and keys arrive as a checklist.

[Read the Mailgun guide](https://nextmail.sh/docs/knowledge/developers/switch-from-mailgun.md)

## Webhook events, renamed.

Each Mailgun event and the Nextmail event that replaces it. Every request carries one event, signed.

| Mailgun | Nextmail |
| --- | --- |
| `accepted` | `email.sent` |
| `delivered` | `email.delivered` |
| `failed (temporary)` | `email.delivery_delayed` |
| `failed (permanent)` | `email.bounced` |
| `complained` | `email.complained` |
| `opened` | `email.opened` |
| `clicked` | `email.clicked` |
| `unsubscribed` | `contact.unsubscribed` |

## Moving from Mailgun, answered.

## Moving from somewhere else?

Every guide has the same converter, field map and checklist.

- [Resend Migration guide Keep your code on the compatible API, or convert it.](https://nextmail.sh/migrate/resend.md)
- [SendGrid Migration guide Personalizations, dynamic templates and event webhooks.](https://nextmail.sh/migrate/sendgrid.md)
- [Postmark Migration guide Server tokens, message streams and templates.](https://nextmail.sh/migrate/postmark.md)

## Converted? Create the key it reads.

A workspace takes a minute. Add your domain, create an API key and set NEXTMAIL\_API\_KEY.

[Open mail](https://nextmail.sh/mail/inbox) [Get Started](https://nextmail.sh/signup.md)[Read the SDK docs](https://nextmail.sh/docs/sdk.md)
