Mailgun Integration

How to use Mailgun with MagicBell

Deliver email notifications with your Mailgun account

To configure Mailgun for your MagicBell project, follow these steps:

  1. Sign up for Mailgun and obtain an API key. Note: We do not support Mailgun's EU region at this time.
  2. From the Channels page in your dashboard, click the ⚙ icon next to Email to access Email Channel Settings.
  3. Under Mailgun, enable the provider and enter the API key from step 1 and your sender domain. You can find the sender domain under your MailGun dashboard. Sometimes, it is named "sending domain".
  4. Add the email address and name you want your notification emails to come from. Then click Save.
You can optionally configure a custom from email address and name.

Once your account is set up, MagicBell will automatically deliver email notifications through your Mailgun account, no additional work is needed.

Sending emails with additional or unique content

Our create notifications endpoint allows you to customize the content sent to Mailgun by setting notification.overrides.

The notification.overrides parameter accepts all of the Mailgun's Messages API body parameters. If there are common parameters in notification.overrides and notifications, then notification.overrides will override the parameters in notifications.

Below is an example of a tagged message with custom headers.

json
{
  "notification": {
    "title": "We're processing your order",
    "content": "<p>Thank you for your order. We'll notify you when these items are ready.</p>",
    "recipients": [
      {
        "email": "dan@example.com"
      }
    ],
    "overrides": {
      "providers": {
        "mailgun": {
          "o:tag": "onboarding",
          "h:X-Original-To": "devs@example.com"
        }
      }
    }
  }
}

Using Mailgun email templates

In addition to our own email templates, MagicBell can deliver email notifications using MailGun's.

Create a template in Mailgun, and grab its ID. Then create a notification with the template attribute set in notification.overrides.providers.mailgun. MagicBell will use custom_attributes to fill in your template.

json
{
  "notification": {
    "title": "We're processing your order",
    "content": "<p>Thank you for your order. We'll notify you when these items are ready.</p>",
    "recipients": [
      {
        "email": "dan@example.com"
      }
    ],
    "custom_attributes": {
      "name": "Dan",
      "company_name": "Example Inc"
    },
    "overrides": {
      "providers": {
        "mailgun": {
          "template": "incident_report"
        }
      }
    }
  }
}