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 Settings Channels page in your dashboard, select Add Provider Mailgun.
  3. 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.

Provider Overrides

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

The notification.overrides.mailgun parameter accepts all the body parameters of Mailgun's Messages API.

Provider-specific parameters in notification.overrides take precedence over the ones specified in notification.

Example: Tag an email and set a custom header

{
  "notification": {
    "title": "We are processing your order",
    "content": "

Thank you for your order. We will notify you when these items are ready.

", "recipients": [ { "email": "dan@example.com" } ], "overrides": { "providers": { "mailgun": { "o:tag": "onboarding", "h:X-Original-To": "devs@example.com" } } } } }

Example: Using Mailgun email templates

In addition to our own email templates, MagicBell can render email notifications using Mailgun's.

After creating a template in Mailgun, you can specify its ID in notification.overrides.providers.mailgun.template and the values for substitution in notification.custom_attributes:

{
  "notification": {
    "title": "We are processing your order",
    "content": "

Thank you for your order. We will notify you when these items are ready.

", "recipients": [ { "email": "dan@example.com" } ], "custom_attributes": { "name": "Dan", "company_name": "Example Inc" }, "overrides": { "providers": { "mailgun": { "template": "MAILGUN_TEMPLATE_ID" } } } } }

Keep in mind that the content of the notification is ignored when you use a template. Mailgun will use the template content instead.