Skip to content

Mailgun API (3.0.0)

Mailgun API defined by OpenAPI Specification (OAS) 3.1.0

Download OpenAPI description
Languages
Servers
US Mailgun

https://api.mailgun.net/

EU Mailgun

https://api.eu.mailgun.net/

Messages

Send email two ways via our REST API:

  1. Send emails using MIME format using a MIME building library
  2. Submit the individual parts (Text, html, attachments, etc.)

Reminder: You can also send email via SMTP with Mailgun. Please reference the user manual.

Operations

Domains

Domains API manages domains, domain keys and DNS verification.

Operations

Domain Keys

An authentication standard used to prevent email spoofing.

Operations

Domain Tracking

Mailgun offers tracking for clicks, unsubscribes, and opens, with optional HTTPS protocol support on tracking URLs. To enable HTTPS, Mailgun uses Let’s Encrypt with HTTP-01 challenges through your existing tracking CNAME record to issue a TLS certificate. This setup also includes support for HTTP Strict Transport Security (HSTS) for enhanced security.

Operations

DKIM Security

Automatic Sender Security DKIM Key APIs. To enable this feature please see 'Update a domain' API docs.

Operations

Webhooks

Webhooks API manages domain's webhooks. You can create, access and delete webhooks programmatically.

Operations

Metrics

The Mailgun Metrics API provides programmatic access to detailed analytics data about your email sending activity. This API allows you to query, filter, and analyze email performance metrics to gain insights into deliverability, engagement, and overall sending health.

Operations

Request

Queries filtered metrics for an account

Security
basicAuth
Bodyrequired
startstring

A start date (default: 7 days before current time). Must be in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14

endstring

An end date (default: current time). Must be in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14

resolutionstring

A resolution in the format of 'day' 'hour' 'month'. Default is day.

durationstring

A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.

dimensionsArray of strings(github.com-mailgun-analytics-client-golang-DimensionName)

Attributes of the metric data such as 'subaccount'. See dimensions

Items Enum ValueDescription
bot

The automated system that engaged with the email, e.g. apple, gmail

country

Country from which the email was sent, e.g. US, FR, MX

ip_pool

IP pool used to send the email

recipient_domain

Recipient domain, e.g. gmail.com

recipient_provider

Email service provider of the recipient, e.g. Gmail, Outlook US, Apple

ip

IP address used to send the email

domain

Domain used to send the email, e.g. example.com

tag

Custom tag attached to the message

device

Type of device used to send the email, e.g. mobile, desktop

subaccount

Subaccount identifier

metricsArray of strings(github.com-mailgun-analytics-client-golang-Metric)

Name of the metrics to receive the stats for such as 'processed_count'. See metrics

Items Enum ValueDescription
accepted_incoming_count

Mailgun accepted the API request to forward, and the message has been put in your queue. These accepted events only cover routes, forwards, and mailing lists. Mailing lists will record a single accepted incoming event, with emails sent to recipients recording their own accepted outgoing events.

accepted_outgoing_count

Mailgun accepted the API request to send, and the message was put in your queue. Batch sends will result in one additional accepted outgoing event to record the initial batch request. Accepted events are not associated to IP addresses. The “processed” metric can be used in place of accepted to view data by IP.

accepted_count

A sum of incoming and outgoing accepted events. This includes all accepted emails to be sent as well as routes, forwards, mailing lists, and batch events. To only view accepted events on emails sent to recipients, use the Accepted Outgoing metric. Accepted events are not associated to IP addresses. The “processed” metric can be used in place of accepted to view similar data by IP.

delivered_smtp_count

The count of delivered events for emails sent to recipient addresses.

delivered_http_count

The count of delivered events for routes and forwards.

delivered_optimized_count

Emails delivered with Send Time Optimization.

delivered_count

Mailgun sent the email and it was accepted by the recipient email server.

processed_count

Messages processed after being accepted. Processed messages are billed to your account at the end of the month.

sent_count

A count of all sent messages. This includes delivered and failed messages, but does not include suppressed messages.

opened_count

The email recipient opened the email and enabled image viewing. Tracking must be turned on.

filterobject

Filters to apply to the query.

include_subaccountsboolean

Include stats from all subaccounts.

include_aggregatesboolean

Include top-level aggregate metrics.

curl -i -X POST \
  -u <username>:<password> \
  https://api.mailgun.net/v1/analytics/metrics \
  -H 'Content-Type: application/json' \
  -d '{
    "start": "Mon, 13 Nov 2023 20:56:50 -0600",
    "end": "Wed, 20 Dec 2023 20:56:50 -0600",
    "resolution": "month",
    "duration": "1m",
    "dimensions": [
      "time"
    ],
    "metrics": [
      "accepted_count",
      "delivered_count",
      "clicked_rate",
      "opened_rate"
    ],
    "filter": {
      "AND": [
        {
          "attribute": "domain",
          "comparator": "=",
          "values": [
            {
              "label": "example.com",
              "value": "example.com"
            }
          ]
        }
      ]
    },
    "include_subaccounts": true,
    "include_aggregates": true
  }'

Responses

A 200 response

Bodyapplication/json
startstring
endstring
resolutionstring
durationstring
dimensionsArray of strings
paginationobject(github.com-mailgun-analytics-client-golang-Pagination)
itemsArray of objects(github.com-mailgun-analytics-internal-api-RegularItem)required
items[].​dimensionsArray of objects(github.com-mailgun-analytics-client-golang-Dimension)
items[].​metricsobject(github.com-mailgun-analytics-internal-api-RegularMetrics)
aggregatesobject(github.com-mailgun-analytics-internal-api-RegularAggregates)
Response
application/json
{ "start": "Mon, 13 Nov 2023 20:56:50 -0600", "end": "Wed, 20 Dec 2023 20:56:50 -0600", "resolution": "month", "duration": "1m", "pagination": { "sort": "timestamp:asc", "skip": 1, "limit": 10, "total": 1000 }, "items": [ {}, {} ], "aggregates": { "metrics": {} } }

Request

Queries filtered usage metrics for an account

Security
basicAuth
Bodyrequired
startstring

A start date (default: 7 days before current time). Must be in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14

endstring

An end date (default: current time). Must be in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14

resolutionstring

A resolution in the format of 'day' 'hour' 'month'. Default is day.

durationstring

A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.

dimensionsArray of strings(github.com-mailgun-analytics-client-golang-UsageDimensionName)

Attributes of the metric data such as 'subaccount'. See dimensions

Items Enum ValueDescription
subaccount

Subaccount identifier

time

The time that your events occurred

metricsArray of strings(github.com-mailgun-analytics-client-golang-UsageMetric)

Name of the metrics to receive the stats for such as 'processed_count'.

Items Enum ValueDescription
email_validation_count

Total number of email validations performed

email_validation_public_count

Number of email validations performed using the public API

email_validation_valid_count

Number of email validations that returned a valid result

email_validation_single_count

Number of single email validations performed

email_validation_bulk_count

Number of bulk email validations performed

email_validation_list_count

Number of email list validations performed

email_validation_mailgun_count

Number of email validations performed using Mailgun's validation service

email_validation_mailjet_count

Number of email validations performed using Mailjet's validation service

email_preview_count

Total number of email previews generated

email_preview_failed_count

Number of failed email preview generation attempts

filterobject

Filters to apply to the query.

metric_filterobject(github.com-mailgun-analytics-client-golang-FilterPredicateGroup)
include_subaccountsboolean

Include stats from all subaccounts.

include_aggregatesboolean

Include top-level aggregate metrics.

curl -i -X POST \
  -u <username>:<password> \
  https://api.mailgun.net/v1/analytics/usage/metrics \
  -H 'Content-Type: application/json' \
  -d '{
    "start": "Mon, 13 Nov 2023 20:56:50 -0600",
    "end": "Wed, 20 Dec 2023 20:56:50 -0600",
    "resolution": "month",
    "duration": "1m",
    "dimensions": [
      "time"
    ],
    "metrics": [
      "accessibility_count",
      "accessibility_failed_count",
      "archived_count",
      "domain_blocklist_monitoring_count",
      "email_preview_count",
      "email_preview_failed_count",
      "email_validation_bulk_count",
      "email_validation_count",
      "email_validation_list_count",
      "email_validation_mailgun_count",
      "email_validation_mailjet_count",
      "email_validation_public_count",
      "email_validation_single_count",
      "email_validation_valid_count",
      "image_validation_count",
      "image_validation_failed_count",
      "ip_blocklist_monitoring_count",
      "link_validation_count",
      "link_validation_failed_count",
      "processed_count",
      "seed_test_count"
    ],
    "filter": {
      "AND": [
        {
          "attribute": "subaccount",
          "comparator": "=",
          "values": [
            {
              "label": "12345",
              "value": "12345"
            }
          ]
        }
      ]
    },
    "include_subaccounts": true,
    "include_aggregates": true
  }'

Responses

A 200 response

Bodyapplication/json
startstring
endstring
resolutionstring
durationstring
dimensionsArray of strings
paginationobject(github.com-mailgun-analytics-client-golang-Pagination)
itemsArray of objects(github.com-mailgun-analytics-internal-api-UsageItem)required
items[].​dimensionsArray of objects(github.com-mailgun-analytics-client-golang-Dimension)
items[].​metricsobject(github.com-mailgun-analytics-internal-api-UsageMetrics)
aggregatesobject(github.com-mailgun-analytics-internal-api-UsageAggregates)
Response
application/json
{ "start": "Mon, 13 Nov 2023 20:56:50 -0600", "end": "Wed, 20 Dec 2023 20:56:50 -0600", "resolution": "month", "duration": "1m", "pagination": { "sort": "timestamp:asc", "skip": 1, "limit": 10, "total": 1000 }, "items": [ {}, {} ], "aggregates": { "metrics": {} } }

Logs

Mailgun keeps track of every inbound and outbound message event and stores this log data. This data can be queried and filtered to provide insights into the health of your email infrastructure.

Operations
Operations

Tags New

Mailgun allows you to tag your email with unique identifiers. Tags are visible via our analytics tags API endpoint.

Operations

Stats

Mailgun collects many different events and generates event statistics which are available in your Control Panel. This data is also available via our stats API endpoint.

WARNING: This API is deprecated in favor of our Metrics API.

Operations

Tags

Mailgun lets you tag each outgoing message with a custom value. When you access stats on your messages, they will be aggregated by these tags.

WARNING: This API is deprecated in favor of our new Tags API.

Operations

Events

Mailgun keeps track of every inbound and outbound message event and stores this data for at least 3 days.

WARNING: This API is deprecated in favor of our Logs API.

Operations

Alerts

Mailgun allows you to get instant notifications on the sending metrics that matter most, configured specifically for your unique business needs and assets. Route these alerts to the channels your team relies on. Stay on top of sending performance without the need to manually monitor.

Operations

Unsubscribe

Unsubscribe list stores email addresses of recipients who unsubscribed from your mailings by clicking a Mailgun generated unsubscribe link.

Operations

Complaints

Email addresses of recipients who marked your messages as a spam (for ESPs that support FBL).

Operations

Bounces

Bounces - Bounce list stores events of delivery failures due to permanent recipient mailbox errors such as non-existent mailbox. Soft bounces (for example, mailbox is full) and other failures (for example, ESP rejects an email because it thinks it is spam) are not added to the list.

Operations

Allowlist

The allowlist API provides the ability to allowlist specific addresses from being added to bounce list. You can allowlist by domain name (i.e example.com) or by specific address (i.e. alice@example.com). Mailgun doesn’t add an address to bounce list if the address is allowlisted. This API is very useful if you test against your private services and don’t want to constantly clean up bounce lists

Operations

Routes

Define a list of routes to handle incoming emails. When a message matches a route expression, Mailgun can forward it on to your application via HTTP or another email address, or store the message temporarily (3 days) for subsequent retrieval.

Operations

Mailing Lists

Programatically create mailing lists.

Operations

Templates

This API allows you to store predefined templates and use them to send messages using the Sending API.

Operations

IP Pools

IP Pools allow you to group your dedicated IPs into customized "pools" to help manage your sending reputation for different mail sending streams.

Operations

Dynamic IP Pools

Dynamic IP Pools allow you to group your dedicated IPs into customized "pools" based on sender reputation. Domains enrolled in Dynamic IP Pools will be assigned to a pool based on the result of periodic health checks.

Operations

IPs

The IP API endpoint allows you to access information regarding the IPs allocated to your Mailgun account that are used for outbound sending.

Operations
Operations

Subaccounts

Mailgun supports the creation, modification, and deletion of subaccounts. A subaccount is a child account of a parent account. The parent account can have multiple subaccounts. The subaccounts are created and managed by the parent account.

Operations

Custom Message Limit

The custom message limit imposes a hard limit on how many messages your account can send during a calendar month.

Operations

Account Management

Perform account-level CRUD operations.

Operations

Keys

The Keys API lets you view and manage API keys.

Operations

Credentials

The Credentials API lets you view and manage SMTP credentials.

Operations

IP Allowlist

The IP Allowlist API lets you view and manage allowlisted IP addresses to which API key and SMTP credential usage is restricted.

Operations

Users

Mailgun API supports viewing user entities.

Operations