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

Account Webhooks

Webhooks API to manage account-specific webhooks. You can create, retrieve, update, and delete webhooks programmatically. Account-level webhooks are configured independently for US and EU regions. When triggered, webhook URLs are deduplicated by event type, across account and domain levels to prevent redundant webhook sends.

Operations

Domain Webhooks

Webhooks API to manage domain-specific webhooks. You can create, retrieve, update, and delete webhooks programmatically. When triggered, webhook URLs are deduplicated by event type, across account and domain levels to prevent redundant webhook sends.

Operations

Request

Create a list of webhook URLs you'd like to receive Mailgun's POST requests containing event information.

Security
basicAuth
Path
domainstringrequired

The domain name to create the webhook for

Bodymultipart/form-datarequired
idstringrequired

Webhook type to create.

Enum ValueDescription
accepted

The accepted event occurs when Mailgun accepts a message for delivery.

clicked

The clicked event occurs when a recipient clicks a link in the email. This requires click tracking to be enabled for the domain.

opened

The opened event occurs when a recipient opens the email. This requires open tracking to be enabled for the domain.

unsubscribed

The unsubscribed event occurs when a recipient unsubscribes using an unsubscribe mechanism in your email (for example, a list-unsubscribe link).

delivered

The delivered event occurs when an email is successfully delivered to the recipient's mail server.

permanent_fail

The permanent_fail event occurs when an email cannot be delivered due to a permanent error.

temporary_fail

The temporary_fail event occurs when an email cannot be delivered due to a temporary error.

complained

The complained event occurs when a recipient marks your email as spam or their email provider registers a spam complaint.

urlstringrequired

url(s) for webhooks to be sent to. Use multiple times to associate more than one url. Maximum of 3 urls for a given webhook type.

curl -i -X POST \
  -u <username>:<password> \
  'https://api.mailgun.net/v3/domains/{domain}/webhooks' \
  -H 'Content-Type: multipart/form-data' \
  -F id=accepted \
  -F url=string

Responses

A 200 response

Bodyapplication/json
messagestringrequired

A message indicating success

webhookobjectrequired

Webhook details

webhook.​urlsArray of strings

List of webhooks

Response
application/json
{ "message": "Webhook has been created", "webhook": { "urls": [] } }

Request

Get the list of url(s) for a webhook identified by its webhook_name.

Security
basicAuth
Path
domain_namestringrequired

Domain name you want webhooks for

webhook_namestringrequired

The webhook type you wish to retrieve.

Enum ValueDescription
accepted

The accepted event occurs when Mailgun accepts a message for delivery.

clicked

The clicked event occurs when a recipient clicks a link in the email. This requires click tracking to be enabled for the domain.

opened

The opened event occurs when a recipient opens the email. This requires open tracking to be enabled for the domain.

unsubscribed

The unsubscribed event occurs when a recipient unsubscribes using an unsubscribe mechanism in your email (for example, a list-unsubscribe link).

delivered

The delivered event occurs when an email is successfully delivered to the recipient's mail server.

permanent_fail

The permanent_fail event occurs when an email cannot be delivered due to a permanent error.

temporary_fail

The temporary_fail event occurs when an email cannot be delivered due to a temporary error.

complained

The complained event occurs when a recipient marks your email as spam or their email provider registers a spam complaint.

curl -i -X GET \
  -u <username>:<password> \
  'https://api.mailgun.net/v3/domains/{domain_name}/webhooks/{webhook_name}'

Responses

A 200 response

Bodyapplication/json
webhookobjectrequired

List of webhooks

webhook.​urlsArray of strings

List of webhooks

Response
application/json
{ "webhook": { "urls": [] } }

Request

Replace the list of urls by the given one with the url param. Here is the list of supported webhook: accepted, opened, clicked, unsubscribed, delivered, permanent_fail, temporary_fail and complained.

Security
basicAuth
Path
domain_namestringrequired

The name of the domain you want to get webhook from

webhook_namestringrequired

The webhook type to update.

Enum ValueDescription
accepted

The accepted event occurs when Mailgun accepts a message for delivery.

clicked

The clicked event occurs when a recipient clicks a link in the email. This requires click tracking to be enabled for the domain.

opened

The opened event occurs when a recipient opens the email. This requires open tracking to be enabled for the domain.

unsubscribed

The unsubscribed event occurs when a recipient unsubscribes using an unsubscribe mechanism in your email (for example, a list-unsubscribe link).

delivered

The delivered event occurs when an email is successfully delivered to the recipient's mail server.

permanent_fail

The permanent_fail event occurs when an email cannot be delivered due to a permanent error.

temporary_fail

The temporary_fail event occurs when an email cannot be delivered due to a temporary error.

complained

The complained event occurs when a recipient marks your email as spam or their email provider registers a spam complaint.

Bodymultipart/form-datarequired
urlstringrequired

New url(s) to associate to webhook. Use multiple times to associate more than one url. Maximum of 3 urls for a given type.

curl -i -X PUT \
  -u <username>:<password> \
  'https://api.mailgun.net/v3/domains/{domain_name}/webhooks/{webhook_name}' \
  -H 'Content-Type: multipart/form-data' \
  -F url=string

Responses

A 200 response

Bodyapplication/json
messagestringrequired

A message indicating success

webhookobjectrequired

Webhook details

webhook.​urlsArray of strings

List of webhooks

Response
application/json
{ "message": "Webhook has been updated", "webhook": { "urls": [] } }

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

Logs

Mailgun keeps track of every inbound and outbound message event and stores this log data. Using this logs API, 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

Limits

Mailgun allows you to set limits on your subaccounts to help you manage usage and costs. You can create, update, retrieve, and delete limits for various pre-send features such as email previews and email validations.

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