Everything an AI agent can do with the Mailgun API.

A reference guide for building AI agents: every method, how to authenticate, and the permissions each one needs.

Endpoints42
API versionv3
Last updated23 June 2026
Orientation

How the Mailgun API works.

The Mailgun API is how an app or AI agent works with an email-sending account: sending messages to recipients, managing sending domains and mailing lists, querying delivery and engagement events, and maintaining the bounce, unsubscribe, and complaint lists. Access is granted through an API key sent as Basic Auth, and a role-based or domain-restricted key limits what that key can reach. Mailgun can also push delivery events to a registered webhook URL when a message is delivered, opened, clicked, or fails.

42Endpoints
10Capability groups
17Read
25Write
3Permissions
Authentication
Every call authenticates over HTTP Basic Auth, with the literal username 'api' and an API key as the password, for example api:YOUR_API_KEY. A primary account key reaches all operations across the account's domains. Newer role-based keys are created with one of four roles, Admin, Developer, Analyst, or Support, and a Domain Sending Key is restricted to posting messages for a single domain. A key's value is shown once at creation and cannot be retrieved later.
Permissions
Access depends on the kind of key. A primary account key carries full create, read, update, and delete access. A role-based key is fixed to its role: Admin has full administrative access, Developer reaches the technical sending and integration endpoints, Analyst is read-only over data and metrics, and Support reads most endpoints with write on specific management ones. A role cannot be changed after the key is created, so changing access means making a new key and revoking the old one. A Domain Sending Key only reaches the message-sending endpoints for one domain.
Versioning
Mailgun versions each endpoint in its path rather than across the whole API, so some methods may sit on a different version than others. Most sit on v3, while domains, account-level templates, and webhook batch updates sit on v4, and API keys and analytics sit on v1. There is no single dated API version; changes ship through the Mailgun release notes.
Data model
The API is resource-oriented over HTTPS, with a US host at https://api.mailgun.net and an EU host at https://api.eu.mailgun.net, and an account's data lives in one region. Sending, suppressions, templates, events, and webhooks are scoped to a domain, while mailing lists, routes, analytics, and API keys are account-level. Events record every inbound and outbound message for at least 3 days, and webhooks push delivery and engagement events to a registered URL.
Connect & authenticate

Connection & authentication methods.

How an app or AI agent connects to Mailgun determines what it can reach. There is a route for making calls and a route for receiving events, and each is governed by the API key behind it and the role that key carries.

Ways to connect

REST API

The REST API answers at https://api.mailgun.net for the US region and https://api.eu.mailgun.net for the EU region. Each endpoint carries its own version segment in the path, mostly v3 with newer areas on v4 and v1.

Best forConnecting an app or AI agent to Mailgun.
Governed byThe API key and the role it carries.
Docs ↗

Webhooks

Webhooks deliver delivery and engagement events to a registered HTTPS endpoint, and each payload is signed so the receiver can confirm it came from Mailgun. They are configured per domain and per event type, with account-level webhooks fanning out across all domains.

Best forReceiving delivery and engagement events without polling.
Governed byThe API key and the role it carries.
Docs ↗

MCP server (Model Context Protocol)

Mailgun publishes an open-source MCP server that lets an agent call Mailgun through the Model Context Protocol, covering messaging, domains, webhooks, routes, mailing lists, templates, and analytics. It runs locally from the source at github.com/mailgun/mailgun-mcp-server, takes the API key as an environment variable, and there is no hosted version.

Best forConnecting an AI agent to Mailgun through the Model Context Protocol.
Governed byThe API key passed to the server, and the role it carries.
Docs ↗
Authentication

Account API key

A primary account API key authenticates over HTTP Basic Auth, with the literal username 'api' and the key as the password, and reaches all create, read, update, and delete operations across the account's domains.

TokenAccount API key
Best forFull account access
Docs ↗

Role-based API key

A role-based key is created with one of four roles that fix its access: Admin for full administrative access, Developer for the technical sending and integration endpoints, Analyst for read-only data and metrics, and Support for read access plus write on specific management endpoints. The role cannot be changed after creation.

TokenRole-based API key
Best forLeast-privilege access by role
Docs ↗

Domain Sending Key

A Domain Sending Key is restricted to posting messages for a single domain, reaching only the messages and messages.mime endpoints, so it cannot read data or change configuration.

TokenDomain Sending Key
Best forSend-only access scoped to one domain
Docs ↗
Capability map

What an AI agent can do in Mailgun.

The Mailgun API is split into areas an agent can act on, like sending mail, managing domains, mailing lists and members, stored templates, delivery events, suppression lists, inbound routes, and webhooks. Each area has its own methods, and a write in some areas sends real email or removes a sending domain.

Messages

5 endpoints

Send email from standard fields or a built MIME string, retrieve and resend a stored message, and clear the scheduled queue.

Writes here send real email to real recipients.
View endpoints

Domains

6 endpoints

List, read, create, and update sending domains, verify their DNS records, and delete a domain.

Writes here change or remove a real sending domain.
View endpoints

Mailing lists & members

7 endpoints

List, create, read, update, and delete mailing lists, and manage the members on each list.

Writes here add or remove people from a marketing audience.
View endpoints

Templates

5 endpoints

List, create, read, update, and delete stored templates, and manage their versions.

Writes here change the templates used for real email.
View endpoints

Events

1 endpoint

Query the log of inbound and outbound message events for a domain.

Reads here return recipient addresses and message metadata.
View endpoints

Suppressions

5 endpoints

Read and manage the bounce, unsubscribe, and complaint lists that stop Mailgun sending to an address.

Writes here change who an account can and cannot email.
View endpoints

Routes

4 endpoints

List, create, read, update, and delete the routes that handle incoming email.

Writes here change how inbound email is forwarded or stored.
View endpoints

Webhooks

4 endpoints

List, create, read, update, and delete the webhooks that receive a domain's delivery events.

Writes here change where delivery events are sent.
View endpoints

Metrics & analytics

2 endpoints

Query filtered sending and usage metrics for an account.

Reads here return account-wide sending statistics.
View endpoints

API keys

3 endpoints

List, create, and delete the API keys an account uses to authenticate.

Writes here create or revoke credentials that reach the account.
View endpoints
Endpoint reference

Every Mailgun API method.

Filter by method, access, or permission, or search any path. Select a row for version detail, rate limits, the related webhook event, and the source.

MethodEndpointWhat it doesAccessPermissionVersion

Messages

Send email from standard fields or a built MIME string, retrieve and resend a stored message, and clear the scheduled queue.5

A Domain Sending Key restricts a key to this and the MIME endpoint for a single domain. With role-based keys, sending needs the Developer role; Analyst and Support are read-only for this.

Acts onmessage
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventdelivered
Rate limitStandard limits apply

A Domain Sending Key also covers this endpoint. Role-based keys need the Developer role.

Acts onmessage
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventdelivered
Rate limitStandard limits apply

Stored messages are kept for about 3 days. Any read-capable role can fetch one.

Acts onmessage
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Resending counts as sending, so the Developer role is needed.

Acts onmessage
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventdelivered
Rate limitStandard limits apply

This clears queued mail for the whole domain at once.

Acts onmessage
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Domains

List, read, create, and update sending domains, verify their DNS records, and delete a domain.6

This area sits on v4. Any read-capable role can list domains.

Acts ondomain
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Returns DNS and tracking configuration for the domain.

Acts ondomain
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

As of 9 May 2025 the smtp_login field is no longer returned on creation; SMTP credentials are made through the Credentials endpoint.

Acts ondomain
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Changes sending and tracking behaviour for the domain.

Acts ondomain
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Confirms a domain is ready to send by re-checking its DNS.

Acts ondomain
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Deletion sits on v3 while the rest of the domains area is v4. Removing a domain stops it sending.

Acts ondomain
Permission (capability)Admin
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Mailing lists & members

List, create, read, update, and delete mailing lists, and manage the members on each list.7

Any read-capable role can list mailing lists.

Acts onmailing list
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

A mailing list is addressed by an email alias that fans out to its members.

Acts onmailing list
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Returns the list's settings and member count.

Acts onmailing list
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Removes the list and its membership.

Acts onmailing list
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Returns recipient email addresses and their stored variables.

Acts onlist member
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Bulk variants accept JSON or CSV at members.json and members.csv.

Acts onlist member
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Takes the member off the list without affecting suppression lists.

Acts onlist member
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Templates

List, create, read, update, and delete stored templates, and manage their versions.5

Account-level templates sit on v4; a domain-scoped set sits on v3 under the domain path.

Acts ontemplate
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

A template can be referenced by name when sending.

Acts ontemplate
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Returns the template and, on request, its versions.

Acts ontemplate
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Versions let a template change without breaking existing sends.

Acts ontemplate version
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Removes the template and all its versions.

Acts ontemplate
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Events

Query the log of inbound and outbound message events for a domain.1

Events are kept for at least 3 days. Mailgun directs new work to the Logs API for fuller event tracking.

Acts onevent
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Suppressions

Read and manage the bounce, unsubscribe, and complaint lists that stop Mailgun sending to an address.5

The bounce list holds addresses with permanent delivery failures, like a non-existent mailbox.

Acts onbounce
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Removing an address lets Mailgun attempt delivery to it again.

Acts onbounce
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Holds addresses that clicked a Mailgun unsubscribe link.

Acts onunsubscribe
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventunsubscribed
Rate limitStandard limits apply

Accepts up to 1,000 records per request.

Acts onunsubscribe
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Holds addresses that marked a message as spam.

Acts oncomplaint
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventcomplained
Rate limitStandard limits apply

Routes

List, create, read, update, and delete the routes that handle incoming email.4

Routes match incoming mail and decide what happens to it.

Acts onroute
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

A route can forward matching mail to a URL or address, or store it for about 3 days.

Acts onroute
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Changes the route's match expression or actions.

Acts onroute
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Stops the route from handling further inbound mail.

Acts onroute
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Webhooks

List, create, read, update, and delete the webhooks that receive a domain's delivery events.4

Webhooks are keyed by event type for a domain.

Acts onwebhook
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Creation sits on v4; single-webhook reads and updates sit on v3. URLs are deduplicated by event type across account and domain levels.

Acts onwebhook
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Changes the receiver URL for an event type. A v4 batch update also exists.

Acts onwebhook
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Stops events of that type being delivered to the URL.

Acts onwebhook
Permission (capability)Developer
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Metrics & analytics

Query filtered sending and usage metrics for an account.2

Analytics sits on v1. The query is sent in the request body, so this read uses POST.

Acts onmetric
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Returns account usage rather than per-message delivery data.

Acts onmetric
Permission (capability)Analyst
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

API keys

List, create, and delete the API keys an account uses to authenticate.3

Key management sits on v1 and is an administrative area.

Acts onapi key
Permission (capability)Admin
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

A role-based key takes one of Admin, Analyst, Developer, or Support, and its role cannot be changed after creation. The key value is shown once and cannot be retrieved later.

Acts onapi key
Permission (capability)Admin
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply

Revoking a key immediately stops it authenticating.

Acts onapi key
Permission (capability)Admin
VersionAvailable since the API’s base version
Webhook eventNone
Rate limitStandard limits apply
No endpoints match those filters.
Webhooks

Webhook events.

Mailgun can notify an app when something happens to a message it sent, like the message being delivered, opened, clicked, or failing to deliver. It posts a signed payload to a registered HTTPS endpoint, so an integration learns about delivery and engagement without polling.

EventWhat it signalsTriggered by
deliveredFires when Mailgun successfully delivers a message to the recipient's mail server./v3/{domain_name}/messages
/v3/{domain_name}/messages.mime
/v3/domains/{domain_name}/messages/{storage_key}
permanent_fail / temporary_failFires when a message fails to deliver, either permanently, like a non-existent mailbox, or temporarily before a retry./v3/{domain_name}/messages
/v3/{domain_name}/messages.mime
openedFires when a recipient opens a message, where open tracking is enabled for the domain./v3/{domain_name}/messages
/v3/{domain_name}/messages.mime
clickedFires when a recipient clicks a tracked link in a message, where click tracking is enabled./v3/{domain_name}/messages
/v3/{domain_name}/messages.mime
unsubscribedFires when a recipient clicks a Mailgun unsubscribe link, which also adds them to the unsubscribe list./v3/{domain_name}/messages
/v3/{domain_name}/messages.mime
complainedFires when a recipient marks a message as spam, which also adds them to the complaint list./v3/{domain_name}/messages
/v3/{domain_name}/messages.mime
No events match that search.
Rate limits & pagination

Rate limits, pagination & request size.

Mailgun limits how fast an app can call, and returns the remaining quota on each response through rate-limit headers so an integration can pace itself. Sending volume is also capped per account and can be raised with Mailgun.

Request rate

Mailgun rate-limits API calls and reports the state on each response through three headers: X-RateLimit-Limit for the total calls allowed in the current window, X-RateLimit-Remaining for the calls left, and X-RateLimit-Reset for the Unix time when the window resets. The window can vary by API depending on resource usage, and exceeding a limit returns 429. Separately, an account has a sending volume cap, which can be raised by contacting Mailgun. The exact numeric ceilings are not published in the reference, so an integration should read the headers rather than assume a fixed figure.

Pagination

List endpoints return paging links in the response, and a request can set a limit on how many records come back per page. An integration should follow the next and previous paging URLs Mailgun returns rather than building them by hand. Events are kept for at least 3 days, so a query reaches back over that window.

Request size

The maximum message size, including all attachments, headers, and body, is 25MB. Batch sending with recipient variables allows at most 1,000 recipients per request, and the bounce, unsubscribe, and complaint endpoints accept up to 1,000 records per call, with CSV imports up to 25MB.

Errors

Status codes & error handling.

The status codes an agent should handle, and what to do about each.

StatusCodeMeaningWhat to do
400Bad RequestThe request was malformed or missing a required parameter. The response body carries a JSON message key with a human-readable explanation.Read the message field, correct the named parameter, and resend.
401UnauthorizedAuthentication failed. The API key is missing, wrong, or not formatted correctly in the Authorization header.Check the key and that it is sent as HTTP Basic Auth with the username 'api'.
402Request FailedThe parameters were valid but the request failed, often a sending or account restriction.Resolve the account or domain restriction named in the response before retrying.
404Not FoundThe requested resource does not exist, such as a domain, list, or route that is not on the account.Confirm the path and that the resource exists on the account and region.
429Too Many RequestsA rate limit was exceeded. The X-RateLimit-Remaining header reaches 0 and X-RateLimit-Reset gives the reset time.Wait until the X-RateLimit-Reset time, then retry.
500Server ErrorSomething went wrong on Mailgun's side. A 5xx range covers internal errors.Retry after a short delay, and contact Mailgun if it persists.
Versioning & freshness

Version history.

Mailgun versions each endpoint in its path rather than across the whole API, so most methods sit on v3 while newer areas like domains, account templates, and webhook updates sit on v4, and API keys and analytics on v1. Changes ship through the Mailgun release notes.

Version history

What changed, and when

Latest versionv3
v3Current version
Per-endpoint path versioning

Mailgun versions each endpoint in its own path segment rather than versioning the whole API at once. Most endpoints sit on v3, the longest-standing version, while newer areas were introduced on v4 (domains, account templates, webhook batch updates) and v1 (API keys, analytics). There is no single dated API version; changes are announced through the Mailgun release notes.

What changed
  • Most send, suppression, list, route, and event endpoints are served on v3
  • Domains, account-level templates, and webhook batch updates are served on v4
  • API key management and analytics are served on v1
2026-05-12Feature update
Forwards API for inbound email

Mailgun added a dedicated Forwards API for configuring inbound email forwarding with wildcard match patterns, purpose-built for recipient-based processing at scale, alongside the existing Routes API.

What changed
  • Introduced wildcard match patterns that forward incoming messages to recipients, URLs, or storage
2026-02-17Feature update
Account-level webhooks

Account-level webhooks were added, firing on events across all domains and subaccounts, with new domain name and account ID fields in the payload so a single receiver can handle the whole account.

What changed
  • Account-level webhooks fire across all domains and subaccounts
  • Payloads gained domain name and account ID fields
2025-07-08Feature update
Automated IP warm-up API

New endpoints let an integration enable or disable automated IP warm-up and check the current warm-up stage, moving a previously manual process under the API.

What changed
  • Enable, disable, and check the status of automated IP warm-up via the API
2025-05-09Requires migration
SMTP credentials no longer auto-generated on domain creation

Creating a domain through the Domains API stopped returning the smtp_login field, because SMTP credentials are no longer generated automatically. Credentials are now made through the Credentials endpoint or in the UI.

What changed
  • The smtp_login field is no longer returned when a domain is created
  • SMTP credentials are created through the Credentials endpoint instead

Different areas carry different version segments; track the release notes for new endpoints and deprecations.

Mailgun release notes ↗
Questions

Mailgun API, answered.

How does an app authenticate to the Mailgun API?+
Authentication uses HTTP Basic Auth. The username is the literal string 'api' and the password is the API key, sent as api:YOUR_API_KEY in the Authorization header. A primary account key reaches everything on the account, while a Domain Sending Key is limited to posting messages for one domain. The key value is shown once when created and cannot be retrieved again, so a lost key must be replaced.
What's the difference between an account key, a role-based key, and a sending key?+
A primary account key carries full access to every operation across the account's domains. A role-based key is created with one of four roles, Admin, Developer, Analyst, or Support, that fixes what it can reach, and that role cannot be changed afterwards. A Domain Sending Key can only post messages for a single domain, reaching the messages and messages.mime endpoints and nothing else. The role-based and sending keys are how an integration gets least-privilege access.
Which version is each endpoint on?+
Mailgun versions endpoints individually in the path, not across the whole API, so the version segment can differ method to method. Most endpoints sit on v3. Domains, account-level templates, and the webhook batch-update endpoints sit on v4, while API keys and analytics sit on v1. There is no single dated API version to pin; new endpoints and deprecations are announced in the Mailgun release notes.
How does an app receive delivery events instead of polling?+
Webhooks deliver events without polling. A receiver URL is registered for a domain and a set of event types, such as delivered, permanent_fail, opened, clicked, unsubscribed, and complained, and Mailgun posts a signed payload when each fires. The signature lets the receiver confirm the payload came from Mailgun. Account-level webhooks fan out across all domains, and URLs are deduplicated by event type so the same event is not sent twice.
What are the rate limits?+
Mailgun reports rate-limit state on every response through the X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers, and the window can vary by API depending on resource usage. Going over returns 429. Separately, an account has a sending volume cap that can be raised by contacting Mailgun. The reference does not publish fixed numeric ceilings, so an integration should pace itself from the headers rather than assume a set figure.
Does Mailgun have a US and an EU region?+
Yes. The US region is served at https://api.mailgun.net and the EU region at https://api.eu.mailgun.net. An account's data lives in one region, so calls must go to the matching host, and a 404 can mean the resource exists in the other region. The path and authentication are otherwise identical between the two.
Related

More marketing API guides for agents

What is Bollard AI?

Control what every AI agent can do in Mailgun.

Bollard AI sits between a team's AI agents and Mailgun. Grant each agent exactly the access it needs, read or write, area by area, and every call is checked and logged.

  • Set read, write, or full access per agent, never a shared Mailgun key.
  • Denied by default, so an agent reaches only what has been explicitly allowed.
  • Every call recorded in plain English: who, what, where, and the decision.
Mailgun
Email Agent
Send email ActionOffReadFull use
Read delivery events ResourceOffReadFull use
Manage mailing lists ResourceOffReadFull use
Delete a domain ActionOffReadFull use
Per-agent access, set in Bollard AI, not in Mailgun