Skip to main content

Mailgun Setup

Connect your Mailgun account to Optail.

Prerequisites

1. Get Your API Key and Domain

  1. Log in to the Mailgun dashboard
  2. Go to Settings > API Security
  3. Copy your Private API key (or generate a new one)
  4. Note your sending domain (e.g., mg.yourdomain.com)

2. Connect in Optail

Via Dashboard

  1. Go to Providers > Connect Provider
  2. Select Mailgun
  3. Enter a display name (e.g., "Mailgun Production")
  4. Enter your API key and sending domain
  5. Click Connect -- Optail validates by querying your domain info

Via API

curl -X POST https://api.optail.io/v1/providers \
-H "Authorization: Bearer ms_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"providerType": "MAILGUN",
"displayName": "Mailgun Production",
"credentials": {
"apiKey": "key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"domain": "mg.yourdomain.com"
}
}'

3. Verify Your Sending Domain

If you have not already set up your domain in Mailgun:

  1. In Mailgun, go to Sending > Domains > Add New Domain
  2. Enter your sending domain (recommended: use a subdomain like mg.yourdomain.com)
  3. Add the required DNS records:
    • TXT record for SPF
    • TXT records for DKIM (two CNAME records)
    • MX records for receiving (if needed)
    • CNAME record for tracking
  4. Click Verify DNS Settings

4. Configure Webhooks (Optional)

To receive delivery events in Optail:

  1. In Mailgun, go to Sending > Webhooks
  2. For each event type, set the URL to: https://webhooks.optail.io/v1/ingest/mailgun
  3. Configure events: Delivered, Opened, Clicked, Bounced (Permanent Failure), Complained, Unsubscribed, Failed (Temporary)

Mailgun requires setting the webhook URL per event type individually.

Credential Reference

FieldDescription
apiKeyMailgun Private API key (starts with key-).
domainVerified sending domain (e.g., mg.yourdomain.com).