Mailgun Setup
Connect your Mailgun account to Optail.
Prerequisites
- A Mailgun account
- A verified sending domain in Mailgun
1. Get Your API Key and Domain
- Log in to the Mailgun dashboard
- Go to Settings > API Security
- Copy your Private API key (or generate a new one)
- Note your sending domain (e.g.,
mg.yourdomain.com)
2. Connect in Optail
Via Dashboard
- Go to Providers > Connect Provider
- Select Mailgun
- Enter a display name (e.g., "Mailgun Production")
- Enter your API key and sending domain
- 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:
- In Mailgun, go to Sending > Domains > Add New Domain
- Enter your sending domain (recommended: use a subdomain like
mg.yourdomain.com) - 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
- Click Verify DNS Settings
4. Configure Webhooks (Optional)
To receive delivery events in Optail:
- In Mailgun, go to Sending > Webhooks
- For each event type, set the URL to:
https://webhooks.optail.io/v1/ingest/mailgun - Configure events: Delivered, Opened, Clicked, Bounced (Permanent Failure), Complained, Unsubscribed, Failed (Temporary)
Mailgun requires setting the webhook URL per event type individually.
Credential Reference
| Field | Description |
|---|---|
apiKey | Mailgun Private API key (starts with key-). |
domain | Verified sending domain (e.g., mg.yourdomain.com). |