# Connect Mailgun API

**Watch our Mailgun API introduction video then read through our easy to follow documentation with more details below:**

{% embed url="<https://emailteam.wistia.com/medias/jhet9uzyvs>" %}

Unlike SMTP Relay, API integration must be customized for each ESP. If you are a customer and want an API integration for your favorite ESP, please [open a support ticket](https://emaildeliverycom.freshdesk.com/support/tickets/new).&#x20;

{% hint style="info" %}
**API integrations are bidirectional**

To track real-time delivery progress natively in your platform including bounce and complaint rates, use an API implementation such as Mailgun, Sparkpost, or Amazon SES.

Velocity MTA, which comes free with your platform, also tracks real-time delivery over your own IP Addresses.&#x20;
{% endhint %}

While logged in to the backend as administrator, click the connect menu, select Mailgun API, then click Add Mailgun Account.

<div align="left"><figure><img src="/files/PDGuecjhbTNYQLBNMZLs" alt="" width="240"><figcaption></figcaption></figure></div>

<figure><img src="/files/SCG7aZ7w2LKNHwrCjgIp" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Name**

Give your API connection an internal name. This will only be seen by you and is for management purposes only.
{% endhint %}

![](/files/GMXxFY5wdJzYVYtzPVTl)

{% hint style="info" %}
**Finding the correct API Key**

You must use the **private** API key from the Mailgun user menu in the top right of the Mailgun interface, and **NOT** the *Sending* API Key from the Mailgun 'Sending' configuration.
{% endhint %}

![](/files/USqrYhhUs5YiB7Ktdgwr)

<div align="left"><figure><img src="/files/rReOzi7vTpz5si1bD1Fl" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
**Don't use the Sending API Key under the 'Sending' menu on Mailgun.**
{% endhint %}

<figure><img src="/files/7YfnQ8MxsGPKDgWuXGbE" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Adding your Mailgun API Key**

Paste in your Mailgun private API Key.
{% endhint %}

<div align="left"><figure><img src="/files/6t5gAsoNHaGtBRyqx6EI" alt="" width="358"><figcaption></figcaption></figure></div>

{% hint style="info" %}
**Adding a sending domain to Mailgun**

Before you can use your sending domain through the Mailgun API, you must add your domain to Mailgun and verify you're the owner.
{% endhint %}

<figure><img src="/files/o1nqJqRbngVxD03DrAa4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Enter a base domain or subdomain**&#x20;

Most mailbox providers such as Gmail recommend using a subdomain, however, this decision is based on your own preferences and goals. Using 'mg' for 'Mailgun' is a common subdomain seen with Mailgun customers.&#x20;
{% endhint %}

<div align="left"><figure><img src="/files/C3VpcU4IFnebH8kNr2pZ" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
**Verify ownership by adding DKIM/SPF authentication**

It's not necessary to add the suggested MX records in order for your domain to be successfully verified. This decision is based on your own preferences and goals.&#x20;

Follow Mailgun's instructions for adding DKIM/SPF verification records to your DNS provider.
{% endhint %}

<figure><img src="/files/07IltMroqU1YfpeE4hr3" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Mailgun may need a moment to detect the changes you've made to your domain configuration. If it doesn't verify you right away, try again in 1-2 minutes.
{% endhint %}

{% hint style="warning" %}
We recommend you **do not** add Mailgun's open and click tracking, an optional additional step on the same page.&#x20;
{% endhint %}

<figure><img src="/files/p277HeNWAct55PeRTAcI" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Add your verified domain to your platform**

Once your domain has been successfully verified by Mailgun, add it to your platform exactly as it appears on Mailgun.
{% endhint %}

<div align="left"><figure><img src="/files/ePyUNOHWDD9wrQWI3S5t" alt="" width="273"><figcaption></figcaption></figure></div>

{% hint style="info" %}
**White-label tracking links**&#x20;

Unless you change your link domain, your admin\_url domain will be used for your tracking links in your email messages. You can add a custom link to automatically match your domain branding for mail sent through this API connection, no further action is required beyond this step for it to work.&#x20;
{% endhint %}

{% hint style="warning" %}
**Make sure you point a DNS A record at your platform IP Address for your tracking link or it will not work.**
{% endhint %}

<div align="left"><figure><img src="/files/ofi85VBH6SJqDPjnGC0w" alt="" width="251"><figcaption></figcaption></figure></div>

{% hint style="info" %}
**Next Steps**

Return to the [getting ready to send page](/docs/introduction/getting-ready-to-send.md) and follow the instructions to start using your newly configured Mailgun API connection:
{% endhint %}

**Additional information**

{% hint style="success" %}
**Webhook integration verification**

After you send your first message successfully through the platform using your Mailgun API connection, you should start seeing webhooks appear under Sending -> Webhooks in the Mailgun interface. This means your integration is fully working.&#x20;
{% endhint %}

{% hint style="warning" %}
**Make sure you have the correct domain chosen**
{% endhint %}

<figure><img src="/files/b43oNVbTRDPlapvI0cfF" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/4DFRpeLW5Xx7ss2yIwb6" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Next Steps**

Return to the [getting ready to send page](/docs/introduction/getting-ready-to-send.md) and follow the instructions to start using your newly configured SMTP Relay connection:
{% endhint %}

{% content-ref url="/pages/Rx5UHIY9qq3KOGGX16x2" %}
[Getting ready to send](/docs/introduction/getting-ready-to-send.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.emaildelivery.com/docs/introduction/connect-mailgun-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
