Mailgun
Configure Mailgun for email sending in Lunogram
Mailgun is a powerful email API for sending, receiving, and tracking emails. Lunogram delivers email through the Mailgun HTTP API and ingests Mailgun's webhooks for delivery, bounce, complaint, and engagement events.
Features
- Email sending via the Mailgun Messages API
- US and EU API regions
- Webhook ingestion for delivery, bounce, complaint, open, click, and unsubscribe events
- Optional webhook signature verification
Setup
1. Create a Mailgun Account
Create an account at mailgun.com. Mailgun offers a free trial that lets you send to authorized recipients while you verify your domain.
2. Add and Verify Your Domain
- Go to Sending → Domains in the Mailgun dashboard
- Click Add New Domain and enter your sending domain (for example
mg.example.com) - Add the DNS records Mailgun provides (SPF, DKIM, and the tracking CNAME)
- Wait for verification to complete
Mailgun hosts domains in two regions. Make sure you note whether your domain lives in the US or EU region — you'll need this when configuring the integration.
3. Get Your API Key
- Open Settings → API Keys in the Mailgun dashboard
- Copy your Private API key
4. Configure in Lunogram
- Open your Lunogram project settings
- Navigate to Integrations and click Add Integration
- Select Mailgun from the list of providers
- Enter your configuration:
- Mailgun API Key: Your private API key
- API Region:
USorEU(must match where your domain is hosted) - Mailgun Domain: Your verified sending domain (e.g.
mg.example.com) - Webhook Signing Key (optional): Used to verify incoming webhooks
- Click Save to create the provider
Configuration Options
| Field | Required | Description |
|---|---|---|
| Mailgun API Key | Yes | Your private Mailgun API key |
| API Region | No | US (default) or EU, matching your domain's region |
| Mailgun Domain | Yes | The verified domain messages are sent from |
| Webhook Signing Key | No | Mailgun HTTP webhook signing key used to verify webhook signatures |
Webhooks
Lunogram exposes a webhook endpoint for your Mailgun integration that maps Mailgun events to delivery status updates:
| Mailgun event | Lunogram event |
|---|---|
accepted | sent |
delivered | delivered |
failed (temporary) | deferred |
failed (permanent) | bounced |
opened | opened |
clicked | clicked |
complained | complained |
unsubscribed | unsubscribed |
To enable webhooks:
- Copy the webhook URL shown for the Mailgun integration in Lunogram
- In Mailgun, go to Sending → Webhooks for your domain and add the URL for each event type you want to track
- (Recommended) Copy the HTTP webhook signing key from Settings → Webhooks into the integration's Webhook Signing Key field so Lunogram can verify that incoming requests originate from Mailgun
Email Format
Mailgun supports both HTML and plain text emails. When creating templates in Lunogram:
- HTML: Rich formatted emails with images, buttons, and styling
- Plain Text: Simple text fallback for email clients that don't support HTML
Troubleshooting
Emails Not Sending
- Verify your API key is correct and active
- Confirm the API Region matches where your domain is hosted (a US key cannot send through an EU domain)
- Ensure the domain is verified and the "from" address uses that domain
Webhooks Not Updating Status
- Confirm the webhook URL is registered in Mailgun for the relevant events
- If you set a signing key in Lunogram, make sure it matches the key in Mailgun
- Check the Mailgun logs for delivery attempts to the webhook URL