> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sendpost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Setting Up Mailgun Integration

> Configure Mailgun as a Third-Party Sending Provider in SendPost with automatic webhook setup.

## Prerequisites

Before setting up the Mailgun integration, ensure you have:

### 1. Mailgun Account

* An active Mailgun account
* A verified sending domain configured in Mailgun

### 2. Mailgun API Key

To create an API key in Mailgun:

<Steps>
  <Step title="Log in to Mailgun">
    Log in to your [Mailgun Dashboard](https://app.mailgun.com)
  </Step>

  <Step title="Navigate to API Keys">
    Go to **Settings** → **API Security** → **API Keys**
  </Step>

  <Step title="Create API Key">
    Click **Create API Key** or use your existing primary API key
  </Step>

  <Step title="Set Permissions">
    Ensure the API key has full access permissions for:

    * **Sending**: Required for email delivery
    * **Webhooks**: Required for event tracking
  </Step>

  <Step title="Save Your Key">
    **Copy your API key** (you may not be able to see it again)
  </Step>
</Steps>

### 3. Mailgun Domain

You'll need your Mailgun sending domain (e.g., `mg.yourdomain.com` or `yourdomain.com`). This is configured in Mailgun under **Sending** → **Domains**.

### 4. SendPost Account

* A SendPost account with admin access
* At least one sub-account created

***

## Setting Up Mailgun Integration

### Step 1: Navigate to Providers

1. Log in to your [SendPost Dashboard](https://app.sendpost.io)
2. Go to **Settings** → **Providers** (or navigate to the Providers page)
3. Click the **NEW** button

### Step 2: Configure Mailgun Provider

1. **Name**: Enter a descriptive name (e.g., "Production Mailgun", "Marketing Mailgun")
2. **Type**: Select **Mailgun** from the dropdown
3. **Key**: Paste your Mailgun API key
4. **Domain**: Enter your Mailgun sending domain (e.g., `mg.yourdomain.com`)
5. Click **Save**

<Note>
  If you're using Mailgun's EU region, you may need to specify the EU API endpoint. Contact support for assistance with EU region configuration.
</Note>

### Step 3: Automatic Webhook Configuration

When you save the provider, SendPost automatically:

<Check>Registers webhooks with Mailgun for each event type</Check>
<Check>Configures all supported events for tracking</Check>
<Check>Creates the necessary processing infrastructure</Check>

**Webhook URL Format**: `https://api.sendpost.io/tpsp/mailgun/account/{your-account-id}`

**Events Configured**:

* Accepted (sent)
* Delivered
* Failed (bounced)
* Rejected
* Opened
* Clicked
* Complained (spam reports)
* Unsubscribed

<Info>
  Mailgun requires a separate webhook registration for each event type, unlike other providers that use a single webhook. SendPost handles this automatically.
</Info>

### Step 4: Configure IP Pool for Mailgun Routing

Before sending emails via Mailgun, you need to configure an IP Pool in SendPost that routes traffic to your Mailgun provider.

#### Why IP Pools?

IP Pools in SendPost allow you to control how your email traffic is distributed between SendPost's native infrastructure and third-party providers like Mailgun. This enables:

* **Volume-based routing**: Split your email volume between Mailgun and SendPost infrastructure
* **Easy traffic management**: Adjust the percentage of emails sent via Mailgun vs SendPost at any time
* **Gradual migration**: Start with a small percentage on Mailgun and increase as needed
* **Failover capability**: Route traffic to Mailgun when SendPost IPs are warming up

#### Setting Up IP Pool for Mailgun

<Steps>
  <Step title="Create IP Pool">
    1. Go to **Settings** → **IP Pools** in your SendPost dashboard
    2. Click **Create New IP Pool**
    3. Enter a descriptive name (e.g., "mailgun-pool" or "transactional-mailgun")
  </Step>

  <Step title="Configure Routing">
    1. In the IP Pool settings, configure the routing to use your Mailgun provider
    2. Set the volume percentage you want to route through Mailgun
    3. You can easily adjust this percentage later to control traffic distribution
  </Step>

  <Step title="Save Configuration">
    Save your IP Pool configuration. The pool name will be used in your API calls.
  </Step>
</Steps>

#### Volume-Based Routing

You can configure what percentage of your email volume goes through Mailgun vs SendPost's native infrastructure:

| Configuration  | Mailgun                | SendPost Infrastructure |
| -------------- | ---------------------- | ----------------------- |
| 100% Mailgun   | All emails via Mailgun | None                    |
| 50/50 Split    | 50% of emails          | 50% of emails           |
| Mailgun Backup | 0% (failover only)     | 100% primary            |

<Info>
  You can change the volume distribution at any time through the SendPost UI without any code changes.
</Info>

### Step 5: Whitelist Your Sending Domain

You must whitelist the same sending domain in SendPost that you use in Mailgun.

<Warning>
  **Important**: The domain you use for sending emails (e.g., `yourdomain.com`) must be whitelisted in SendPost. This ensures proper email routing and deliverability.
</Warning>

1. Go to **Settings** → **Domains** in your SendPost dashboard
2. Click **Add Domain**
3. Enter the same domain you have configured in Mailgun (e.g., `yourdomain.com`)
4. Complete the domain verification process

<Note>
  If you're using multiple sending domains in Mailgun, you need to whitelist each domain in SendPost.
</Note>

***

## Next Steps

Once your Mailgun integration is set up, you can:

* [Send emails via Mailgun](/guides/mailgun/sending-emails) using the SendPost API
* [Understand event types](/guides/mailgun/event-types) for tracking email status
* [View analytics](/guides/mailgun/analytics) for your Mailgun emails
