Mailgun

Mailgun

Introduction

The Mailgun API is built on HTTP. Our API is RESTful and it:

Mailgun has published Libraries for various languages. You may use our libraries, or your favorite HTTP/REST library available for your programming language, to make HTTP calls to Mailgun. Visit our Libraries page to see HTTP REST libraries we recommend.

To give you an idea of how to use the API, we have annotated our documentation with code samples written in several popular programming languages. Use the language selector at the top to switch between them.

Our samples from quickstart, User Manual, and API Reference provide examples that will function. You’re welcome to copy/paste and run the script to see the API in action.

Base URL

All API URLs referenced in this documentation start with the following base part:

https://api.mailgun.net/v3

Your Mailgun account may contain several email domains. To avoid passing the domain name as a query parameter, most API URLs must include the name of the domain you’re interested in:

https://api.mailgun.net/v3/mydomain.com

Authentication

When you sign up for an account, you are given an API key. You authenticate to the Mailgun API by providing your API key in the request. You can manage your API key in the “Security” tab under the Account section of the Control Panel.

Authentication to the API occurs via HTTP Basic Auth. Use api as the user name and your API key is the password. Here is how you use basic HTTP auth with curl:

curl --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0'

Or you can try the following API call right from your browser:

https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0@api.mailgun.net/v3/samples.mailgun.org/log

Warning: Keep your API key secret!

Date Format

Mailgun returns JSON for all API calls. JSON does not have a built-in date type, dates are passed as strings encoded according to RFC 2822#page-14. This format is native to JavaScript and is also supported by most programming languages out of the box:

'Thu, 13 Oct 2011 18:02:00 GMT'

Errors

CodeDescription
200Everything worked as expected
400Bad Request - Often missing a required parameter
401Unauthorized - No valid API key provided
402Request Failed - Parameters were valid but request failed
404Not Found - The requested item doesn’t exist
500, 502, 503, 504Server Errors - something is wrong on Mailgun’s end

Webhooks

Mailgun can also POST data to your application when events (opens, clicks, bounces, etc.) occur or when you use Routes. You can read more about webhooks and Routes in the User Manual.

Mailgun Regions

Using a single account and billing plan, you can choose to provision new sending domains in the EU environment. Message data never leaves the region in which it is processed. Only a limited amount of account data is replicated globally, giving you a single account from which to manage domains in both the US and the EU. Here are the specifics on the type of data that is replicated globally versus what is region-bound.

GlobalRegion-Bound (US / EU)
Account Information, User Accounts, Billing Details (invoices/plan information), API Keys, Domain NamesDomain Metadata (e.g. SMTP credentials), Messages, Event Logs, Suppressions, Mailing Lists, Tags, Statistics, Routes, IP Addresses

The endpoints you will use for sending/receiving/tracking messages in the EU are below:

ServiceUS EndpointEU Endpoint
REST APIapi.mailgun.netapi.eu.mailgun.net
Outgoing SMTP Serversmtp.mailgun.orgsmtp.eu.mailgun.org
Inbound SMTP Server (Routes)mxa.mailgun.orgmxa.eu.mailgun.org
Inbound SMTP Server (Routes)mxb.mailgun.orgmxb.eu.mailgun.org
Open/Click Tracking Endpointmailgun.orgeu.mailgun.org

Operations

Delete single validation job
Get single validation job
Submit bulk validation job
Get all bulk validation jobs
Validate address (private)
Get domains
Get domain connection settings
Update domain delivery connection settings
Get SMTP credentials for a domain
Create new SMTP credentials
Get single domain
Get list of IPs for a domain
Unassign IP from a domain
Assign IP to domain
Update domain tracking settings for CLICKS
Get domain tracking settings
Update domain tracking settings for OPENS
Update domain tracking settings for UNSUBSCRIBES
Create new domain
Clear domain queue
Get all IPs for an account
Get specific IP
Get mailing lists
Submit validation list job
Get single mailing list by address
Add multiple members to mailing list
Add member to mailing list
Create mailing list
Update mailing list
Delete bounce list
Add single bounce
Delete single complaint
Get all complaints
Add single complaint
Send message with MIME
Get stat items
Get domain stats
Get domain tags
Delete ALL Templates
Create template
Get single template and all versions
Store new version of template
Get single template versions
Delete single unsubscribe
Get domain unsubscribes
Add single unsubscribe
Delete single whitelisted address
Get single whitelisted address
Remove all whitelisted addresses
Get whitelisted addresses
Add whitelisted addresses
Get routes
Create route
Get single route
Update route