Skip to main content

Overview

Mailgun (by Sinch) is an enterprise developer-centric email API engineered for high-throughput transactional and broadcast delivery. In BrokerOS, the Mailgun integration lives in integrations/mail/mailgun/src/index.ts under the Turborepo workspace package @brokeros/int-mail-mailgun. BrokerOS administrators configure Mailgun entirely within the Web UI at Dashboard -> Marketing -> Email -> Settings. All API credentials are encrypted with AES-256-GCM and stored in PostgreSQL (MarketingIntegration).

Architecture and Dispatch Sequence

The Mailgun integration implements the IEmailMarketingProvider contract from @brokeros/types. Outbound marketing and transactional emails submit form-encoded MIME requests to Mailgun’s v3 endpoint.

Step 1: Obtain Credentials from Mailgun

  1. Log into your Mailgun dashboard at app.mailgun.com.
  2. Navigate to Sending -> Domains and add your sending subdomain (e.g. mail.skylinerealty.com).
  3. Add the two TXT records (SPF and DKIM k=rsa; p=...) and MX routing records provided by Mailgun into your DNS management console.
  4. Navigate to Settings -> API Security and copy your primary Private API Key (starting with key-).
  5. Note your account region (US or EU).

Step 2: Connect in the BrokerOS Web Dashboard

In your BrokerOS dashboard:
  1. Navigate to Dashboard -> Marketing -> Email -> Settings.
  2. Select the Providers & Domains tab (/dashboard/marketing/email/settings?tab=providers).
  3. Click Add Provider and choose Mailgun.
  4. Fill in the modal connection fields:
  1. Click Verify & Connect. BrokerOS connects to GET /v3/domains/{domain}, verifies active domain status, encrypts the credentials via AES-256-GCM, and stores them in MarketingIntegration.

Step 3: Configure Webhook Endpoints in Mailgun

To stream live bounce, open, and click metrics into BrokerOS:
  1. In Mailgun, go to Sending -> Webhooks.
  2. Add your BrokerOS webhook destination URL:
  3. Enable events for Delivered Messages, Permanent Failure, Temporary Failure, Clicks, Opens, and Unsubscribes.
  4. Save the webhook. BrokerOS MailgunWebhookParser processes incoming callbacks automatically.

Webhook Event Telemetry Mapping


Integration Implementation Details

The Mailgun integration source code is located in integrations/mail/mailgun/src/index.ts.

Multi-Region Resolution

The client dynamically resolves endpoints based on tenant configuration:

Form-Encoded Dispatch

Outbound batches are encoded as application/x-www-form-urlencoded payloads: