# Mailgun API

**Mailgun API** integrates with [Mailgun’s email delivery service](https://documentation.mailgun.com/), allowing you to send emails with custom recipients, subjects, and content, including attachments. It helps automate notifications, transactional emails, and marketing messages within your pipelines.

## **Parameters**

Take a look at the configuration parameters for the connector. Parameters supported by [Double Braces expressions](https://docs.digibee.com/documentation/connectors-and-triggers/double-braces/overview) are marked with `(DB)`.

### **General tab**

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Description</th><th>Default value</th><th>Data type</th></tr></thead><tbody><tr><td><strong>Account</strong></td><td>The account used by the connector. Supported type: <strong>Basic</strong>.</td><td>N/A</td><td>Account</td></tr><tr><td><strong>Fail On Error</strong></td><td>If the option is activated, the pipeline's execution with an error will be interrupted. Otherwise, the pipeline execution proceeds, but the result will show a false value for the <code>"success"</code> property.</td><td>False</td><td>Boolean</td></tr></tbody></table>

### **Host tab**

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Description</th><th>Default value</th><th>Data type</th></tr></thead><tbody><tr><td><strong>Host</strong> <code>(DB)</code></td><td>The base URL of the Mailgun API.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Path</strong></td><td>The specific Mailgun endpoint to be accessed. The selected path may determine additional configuration options, such as query parameters. For details on each endpoint, refer to the <a href="https://documentation.mailgun.com/docs/mailgun/api-reference/">Mailgun API documentation</a>.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Method</strong></td><td>The HTTP method used for the request.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Multi Part Data</strong> <code>(DB)</code></td><td>Multi Part Data to be sent in the REST call.</td><td>N/A</td><td>JSON</td></tr></tbody></table>

### **Settings tab**

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Description</th><th>Default value</th><th>Data type</th></tr></thead><tbody><tr><td><strong>Connect Timeout (ms)</strong></td><td>Maximum time allowed for establishing a connection, in milliseconds.</td><td>30000</td><td>Integer</td></tr><tr><td><strong>Read Timeout (ms)</strong></td><td>Maximum time allowed for reading data, in milliseconds.</td><td>30000</td><td>Integer</td></tr><tr><td><strong>Stop on Client Error</strong></td><td>When enabled, stops the pipeline execution if a 4xx HTTP error occurs.</td><td>False</td><td>Boolean</td></tr><tr><td><strong>Stop on Server Error</strong></td><td>When enabled, stops the pipeline execution if a 5xx HTTP error occurs.</td><td>False</td><td>Boolean</td></tr><tr><td><strong>Override Response Charset</strong></td><td>When enabled, replaces the charset returned by the endpoint with the one specified in the <strong>Response Charset</strong> property. Otherwise, the charset from the <strong>Content-Type</strong> header is used.</td><td>True</td><td>Boolean</td></tr><tr><td><strong>Response Charset</strong></td><td>Defines the charset to be used when <strong>Override Response Charset</strong> is enabled. Default: UTF-8.</td><td>UTF-8</td><td>String</td></tr></tbody></table>

### **Documentation tab**

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Description</th><th>Default value</th><th>Data type</th></tr></thead><tbody><tr><td><strong>Documentation</strong></td><td>Section for documenting any necessary information about the connector configuration and business rules.</td><td>N/A</td><td>String</td></tr></tbody></table>

## **Usage examples**

### **Sending an email**

This connector allows you to send emails by specifying message components such as `to`, `from`, `subject`, `HTML`, and text parts. If you are using a free plan for testing purposes, you can only send emails to [Authorized Recipients](https://help.mailgun.com/hc/en-us/articles/217531258-Authorized-Recipients).

{% hint style="info" %}
**Required fields:** The `from`, `to`, and `subject` fields must be included in the request body schema for the email to be sent successfully.
{% endhint %}

On the Digibee Integration Platform, you can send emails in two ways:

* By passing the full body directly in the connector
* By using [Double Braces](https://docs.digibee.com/documentation/connectors-and-triggers/double-braces/overview) expressions

<details>

<summary><strong>Passing the full body</strong></summary>

**Connector configuration**

**API tab:**

* **Host:** [`https://api.mailgun.net`](https://api.mailgun.net)
* **Path:** `v3/{domain_name}/messages`
* **Method:** `POST`
* **Path {domain\_name):** `sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org`
* **Header {Content-Type}:** `Multipart/form-data`
* **Multi Part Data:**

```json
{
  "fields": {
    "from": "Mailgun Sandbox <postmaster@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org>",
    "to": "John Doe <john.doe@email.com>",
    "subject": "Hello John",
    "text": "Congratulations John, you just sent an email with Mailgun! You are truly awesome!"
  }
}
```

**Example response:**

```json
{
  "status": 200,
  "statusMessage": "",
  "body": {
    "id": "<20250318144251.422a1712bf6c5a4c@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org>",
    "message": "Queued. Thank you."
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-origin": "*",
    "account-id": "67d2d0ac0f6261b4526226e2",
    "cache-control": "no-store",
    "content-length": "126",
    "content-type": "application/json; charset=utf-8",
    "date": "Tue, 18 Mar 2025 14:42:51 GMT",
    "strict-transport-security": "max-age=63072000; includeSubDomains",
    "x-mailgun-key-id": "623424ea-c0c80f74",
    "x-ratelimit-limit": "80000",
    "x-ratelimit-remaining": "79999",
    "x-ratelimit-reset": "1742308981236",
    "x-recipient-limit": "2000000",
    "x-recipient-remaining": "1999999",
    "x-recipient-reset": "1742308981236",
    "x-server": "influx",
    "x-xss-protection": "1; mode=block"
  }
}
```

</details>

<details>

<summary><strong>Using Double Braces expressions</strong></summary>

To send an email using [Double Braces](https://docs.digibee.com/documentation/connectors-and-triggers/double-braces) expressions, you need to:

1. Place a [**JSON Generator**](https://docs.digibee.com/documentation/connectors-and-triggers/connectors/tools/json-generator) connector before the **Mailgun API** connector.
2. Use the following JSON payload:

```json
{
    "from": "Mailgun Sandbox <postmaster@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org>",
    "to": "John Doe <john.doe@email.com>",
    "subject": "Hello!",
    "text": "Welcome to Digibee"
}
```

3\. In the **Mailgun API** connector, configure:

**API tab:**

* **Host:** [`https://api.mailgun.net`](https://api.mailgun.net)
* **Path:** `v3/{domain_name}/messages`
* **Method:** `POST`
* **Path {domain\_name):** `sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org`
* **Header {Content-Type}:** `Multipart/form-data`
* **Multi Part Data:**

```json
{
  "fields": {
    "from": {{ message.from }},
    "to": {{ message.to }},
    "subject": {{ message.subject}},
    "text": {{ message.text }}
  }
}
```

**Example response:**

```json
{
  "status": 200,
  "statusMessage": "",
  "body": {
    "id": "<20250319125318.152d650c9d0e220e@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org>",
    "message": "Queued. Thank you."
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-origin": "*",
    "account-id": "67d2d0ac0f6261b4526226e2",
    "cache-control": "no-store",
    "content-length": "126",
    "content-type": "application/json; charset=utf-8",
    "date": "Wed, 19 Mar 2025 12:53:18 GMT",
    "strict-transport-security": "max-age=63072000; includeSubDomains",
    "x-mailgun-key-id": "623424ea-c0c80f74",
    "x-ratelimit-limit": "80000",
    "x-ratelimit-remaining": "79999",
    "x-ratelimit-reset": "1742388808749",
    "x-recipient-limit": "2000000",
    "x-recipient-remaining": "1999999",
    "x-recipient-reset": "1742388808749",
    "x-server": "influx",
    "x-xss-protection": "1; mode=block"
  }
}
```

</details>

### **Attaching files to the email**

You can attach one or more files to your email.

<details>

<summary><strong>Single attachment</strong></summary>

Add the `attachment` field to the JSON body, as shown below:

```json
{
  "fields": {
    "from": "Mailgun Sandbox <postmaster@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org>",
    "to": "John Doe <john.doe@email.com>",
    "subject": "Hello!",
    "html":"<h1>Hello</h1><p>This is the email content.</p>",
    "attachment": {{ message.fileName}}
  }
}
```

</details>

<details>

<summary><strong>Multiple attachments</strong></summary>

Each attachment must have a unique identifier while maintaining `attachment` as the base name. You can use variations such as `attachmentPDF`, `attachment2`, or `attachment_2`. See the example:

```json
{
  "fields": {
    "from": "Mailgun Sandbox <postmaster@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org>",
    "to": "Digibee <digibee@email.com>",
    "subject": "Hello!",
    "html":"<h1>Hello</h1><p>This is the email content.</p>",
    "attachment": {{ message.fileName}},
    "attachment2": {{ message.fileName2}}
  }
}
```

{% hint style="warning" %}
If multiple attachments are sent without unique identifiers, only the last attachment will be included in the email.
{% endhint %}

</details>

### **Retrieving a paginated list of events**

Mailgun tracks every inbound and outbound message event and retains this data for at least three days. You can retrieve a paginated list of these events.

For this example, we filter events of type **delivered** and **opened**.

<details>

<summary><strong>Delivered events</strong></summary>

**Connector configuration**

**API tab:**

* **Host:** [`https://api.mailgun.net`](https://api.mailgun.net)
* **Path:** `v3/{domain_name}/events`
* **Method:** `GET`
* **Query {event}:** `delivered`

**Example response:**

```json
{
  "status": 200,
  "statusMessage": "",
  "body": {
    "items": [
      {
        "tags": [
          
        ],
        "delivery-status": {
          "first-delivery-attempt-seconds": 0.28,
          "attempt-no": 1,
          "mx-host": "aspmx.l.google.com",
          "tls": true,
          "utf8": true,
          "code": 250,
          "session-seconds": 1.066,
          "certificate-verified": true,
          "message": "OK",
          "enhanced-code": "",
          "description": ""
        },
        "id": "KEsUGyjdTJ602U6INUgxbA",
        "user-variables": {
          
        },
        "event": "delivered",
        "primary-dkim": "mx._domainkey.sandbox.mgsend.net",
        "flags": {
          "is-test-mode": false,
          "is-authenticated": true,
          "is-system-test": false,
          "is-routed": false
        },
        "message": {
          "size": 420,
          "headers": {
            "from": "Mailgun Sandbox <postmaster@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org>",
            "subject": "Hello!",
            "message-id": "20250318144251.422a1712bf6c5a4c@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org",
            "to": "John Doe <john.doe@email.com>"
          },
          "attachments": [
            
          ]
        },
        "recipient": "john.doe@email.com",
        "recipient-domain": "email.com",
        "log-level": "info",
        "recipient-provider": "Google Workspace",
        "envelope": {
          "targets": "john.doe@email.com",
          "sender": "postmaster@sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org",
          "sending-ip": "159.135.228.60",
          "transport": "smtp"
        },
        "campaigns": [
          
        ],
        "storage": {
          "region": "us-west1",
          "key": "BAABAQXGi0zYUlTqvp1H269ssre_PkBIYw",
          "env": "production",
          "url": "https://storage-us-west1.api.mailgun.net/v3/domains/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/messages/BAABAQXGi0zYUlTqvp1H269ssre_PkBIYw"
        },
        "timestamp": 1742308972.4313374
      }
    ],
    "paging": {
      "previous": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjozMDo0OC44ODMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjozMDo0OC44OTIrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE4VDE0OjQyOjUyLjQzMSswMDowMCIsImUiOiIyMDI1LTAzLTE5VDEyOjMwOjQ4Ljg4MyswMDowMCJ9LCJfZG9jI0tFc1VHeWpkVEo2MDJVNklOVWd4YkEiLFsiZiIsInAiXSxudWxsLFtbImFjY291bnQuaWQiLCI2N2QyZDBhYzBmNjI2MWI0NTI2MjI2ZTIiXSxbImRvbWFpbi5uYW1lIiwic2FuZGJveDE5NDcwMDRiZDhhMTQ5OTZiYzg2MTA5NzhiY2UzN2U3Lm1haWxndW4ub3JnIl0sWyJldmVudCIsImRlbGl2ZXJlZCJdXSwxMDBd",
      "next": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjozMDo0OC44ODMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjozMDo0OC44OTIrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE4VDE0OjQyOjUyLjQzMSswMDowMCIsImUiOiIyMDI1LTAzLTE4VDEyOjMwOjQ4Ljg5MiswMDowMCJ9LCJfZG9jI0tFc1VHeWpkVEo2MDJVNklOVWd4YkEiLFsiZiJdLG51bGwsW1siYWNjb3VudC5pZCIsIjY3ZDJkMGFjMGY2MjYxYjQ1MjYyMjZlMiJdLFsiZG9tYWluLm5hbWUiLCJzYW5kYm94MTk0NzAwNGJkOGExNDk5NmJjODYxMDk3OGJjZTM3ZTcubWFpbGd1bi5vcmciXSxbImV2ZW50IiwiZGVsaXZlcmVkIl1dLDEwMF0=",
      "first": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjozMDo0OC44ODMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjozMDo0OC44OTIrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE5VDEyOjMwOjQ4Ljg4MyswMDowMCIsImUiOiIyMDI1LTAzLTE4VDEyOjMwOjQ4Ljg5MiswMDowMCJ9LG51bGwsWyJmIl0sbnVsbCxbWyJhY2NvdW50LmlkIiwiNjdkMmQwYWMwZjYyNjFiNDUyNjIyNmUyIl0sWyJkb21haW4ubmFtZSIsInNhbmRib3gxOTQ3MDA0YmQ4YTE0OTk2YmM4NjEwOTc4YmNlMzdlNy5tYWlsZ3VuLm9yZyJdLFsiZXZlbnQiLCJkZWxpdmVyZWQiXV0sMTAwXQ==",
      "last": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjozMDo0OC44ODMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjozMDo0OC44OTIrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE4VDEyOjMwOjQ4Ljg5MiswMDowMCIsImUiOiIyMDI1LTAzLTE5VDEyOjMwOjQ4Ljg4MyswMDowMCJ9LG51bGwsWyJmIiwicCJdLG51bGwsW1siYWNjb3VudC5pZCIsIjY3ZDJkMGFjMGY2MjYxYjQ1MjYyMjZlMiJdLFsiZG9tYWluLm5hbWUiLCJzYW5kYm94MTk0NzAwNGJkOGExNDk5NmJjODYxMDk3OGJjZTM3ZTcubWFpbGd1bi5vcmciXSxbImV2ZW50IiwiZGVsaXZlcmVkIl1dLDEwMF0="
    }
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-origin": "*",
    "cache-control": "no-store",
    "content-type": "application/json",
    "date": "Wed, 19 Mar 2025 12:30:48 GMT",
    "server": "TwistedWeb/22.10.0",
    "strict-transport-security": "max-age=63072000; includeSubDomains",
    "x-xss-protection": "1; mode=block"
  }
}
```

</details>

<details>

<summary><strong>Opened events</strong></summary>

**Connector configuration**

**API tab:**

* **Host:** [`https://api.mailgun.net`](https://api.mailgun.net)
* **Path:** `v3/{domain_name}/events`
* **Method:** `GET`
* **Query {event}:** `opened`

**Example response:**

```json
{
  "status": 200,
  "statusMessage": "",
  "body": {
    "items": [
      
    ],
    "paging": {
      "previous": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjo1NTowNi4xMzMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjo1NTowNi4xNDkrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE5VDEyOjU1OjA2LjEzMyswMDowMCIsImUiOiIyMDI1LTAzLTE5VDEyOjU1OjA2LjEzMyswMDowMCJ9LG51bGwsWyJmIiwicCJdLG51bGwsW1siYWNjb3VudC5pZCIsIjY3ZDJkMGFjMGY2MjYxYjQ1MjYyMjZlMiJdLFsiZG9tYWluLm5hbWUiLCJzYW5kYm94MTk0NzAwNGJkOGExNDk5NmJjODYxMDk3OGJjZTM3ZTcubWFpbGd1bi5vcmciXSxbImV2ZW50Iiwib3BlbmVkIl1dLDEwMF0=",
      "next": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjo1NTowNi4xMzMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjo1NTowNi4xNDkrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE5VDEyOjU1OjA2LjEzMyswMDowMCIsImUiOiIyMDI1LTAzLTE4VDEyOjU1OjA2LjE0OSswMDowMCJ9LG51bGwsWyJmIl0sbnVsbCxbWyJhY2NvdW50LmlkIiwiNjdkMmQwYWMwZjYyNjFiNDUyNjIyNmUyIl0sWyJkb21haW4ubmFtZSIsInNhbmRib3gxOTQ3MDA0YmQ4YTE0OTk2YmM4NjEwOTc4YmNlMzdlNy5tYWlsZ3VuLm9yZyJdLFsiZXZlbnQiLCJvcGVuZWQiXV0sMTAwXQ==",
      "first": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjo1NTowNi4xMzMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjo1NTowNi4xNDkrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE5VDEyOjU1OjA2LjEzMyswMDowMCIsImUiOiIyMDI1LTAzLTE4VDEyOjU1OjA2LjE0OSswMDowMCJ9LG51bGwsWyJmIl0sbnVsbCxbWyJhY2NvdW50LmlkIiwiNjdkMmQwYWMwZjYyNjFiNDUyNjIyNmUyIl0sWyJkb21haW4ubmFtZSIsInNhbmRib3gxOTQ3MDA0YmQ4YTE0OTk2YmM4NjEwOTc4YmNlMzdlNy5tYWlsZ3VuLm9yZyJdLFsiZXZlbnQiLCJvcGVuZWQiXV0sMTAwXQ==",
      "last": "https://api.mailgun.net/v3/sandbox1947004bd8a14996bc8610978bce37e7.mailgun.org/events/WzMseyJiIjoiMjAyNS0wMy0xOVQxMjo1NTowNi4xMzMrMDA6MDAiLCJlIjoiMjAyNS0wMy0xOFQxMjo1NTowNi4xNDkrMDA6MDAifSx7ImIiOiIyMDI1LTAzLTE4VDEyOjU1OjA2LjE0OSswMDowMCIsImUiOiIyMDI1LTAzLTE5VDEyOjU1OjA2LjEzMyswMDowMCJ9LG51bGwsWyJmIiwicCJdLG51bGwsW1siYWNjb3VudC5pZCIsIjY3ZDJkMGFjMGY2MjYxYjQ1MjYyMjZlMiJdLFsiZG9tYWluLm5hbWUiLCJzYW5kYm94MTk0NzAwNGJkOGExNDk5NmJjODYxMDk3OGJjZTM3ZTcubWFpbGd1bi5vcmciXSxbImV2ZW50Iiwib3BlbmVkIl1dLDEwMF0="
    }
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-origin": "*",
    "cache-control": "no-store",
    "content-type": "application/json",
    "date": "Wed, 19 Mar 2025 12:55:06 GMT",
    "server": "TwistedWeb/22.10.0",
    "strict-transport-security": "max-age=63072000; includeSubDomains",
    "x-xss-protection": "1; mode=block"
  }
}
```

</details>
