Access the Mailgun API with managed OAuth authentication. Send transactional emails, manage domains, routes, templates, mailing lists, suppressions, and webhooks.
Important: Mailgun API uses application/x-www-form-urlencoded for POST/PUT requests, not JSON.
Reference
List Domains
GET /mailgun/v3/domainsReturns all domains for the account.
Get Domain
GET /mailgun/v3/domains/{domain_name}Create Domain
POST /mailgun/v3/domains
Content-Type: application/x-www-form-urlencoded
name=example.com&smtp_password=supersecretDelete Domain
DELETE /mailgun/v3/domains/{domain_name}Send Message
POST /mailgun/v3/{domain_name}/messages
Content-Type: application/x-www-form-urlencoded
from=sender@example.com&to=recipient@example.com&subject=Hello&text=Hello WorldParameters:
from(required) - Sender email addressto(required) - Recipient(s), comma-separatedcc- CC recipientsbcc- BCC recipientssubject(required) - Email subjecttext- Plain text bodyhtml- HTML bodytemplate- Name of stored template to useo:tag- Tag for trackingo:tracking- Enable/disable tracking (yes/no)o:tracking-clicks- Enable click trackingo:tracking-opens- Enable open trackingh:X-Custom-Header- Custom headers (prefix with h:)v:custom-var- Custom variables for templates (prefix with v:)
Send MIME Message
POST /mailgun/v3/{domain_name}/messages.mime
Content-Type: multipart/form-data
to=recipient@example.com&message=<MIME content>List Events
GET /mailgun/v3/{domain_name}/eventsQuery parameters:
begin- Start time (RFC 2822 or Unix timestamp)end- End timeascending- Sort order (yes/no)limit- Results per page (max 300)event- Filter by event type (accepted, delivered, failed, opened, clicked, unsubscribed, complained, stored)from- Filter by senderto- Filter by recipienttags- Filter by tags
List Routes
GET /mailgun/v3/routesQuery parameters:
skip- Number of records to skiplimit- Number of records to return
Create Route
POST /mailgun/v3/routes
Content-Type: application/x-www-form-urlencoded
priority=0&description=My Route&expression=match_recipient(".*@example.com")&action=forward("https://example.com/webhook")Parameters:
priority- Route priority (lower = higher priority)description- Route descriptionexpression- Filter expression (match_recipient, match_header, catch_all)action- Action(s) to take (forward, store, stop)
Get Route
GET /mailgun/v3/routes/{route_id}Update Route
PUT /mailgun/v3/routes/{route_id}
Content-Type: application/x-www-form-urlencoded
priority=1&description=Updated RouteDelete Route
DELETE /mailgun/v3/routes/{route_id}List Webhooks
GET /mailgun/v3/domains/{domain_name}/webhooksCreate Webhook
POST /mailgun/v3/domains/{domain_name}/webhooks
Content-Type: application/x-www-form-urlencoded
id=delivered&url=https://example.com/webhookWebhook types: accepted, delivered, opened, clicked, unsubscribed, complained, permanent_fail, temporary_fail
Get Webhook
GET /mailgun/v3/domains/{domain_name}/webhooks/{webhook_type}Update Webhook
PUT /mailgun/v3/domains/{domain_name}/webhooks/{webhook_type}
Content-Type: application/x-www-form-urlencoded
url=https://example.com/new-webhookDelete Webhook
DELETE /mailgun/v3/domains/{domain_name}/webhooks/{webhook_type}List Templates
GET /mailgun/v3/{domain_name}/templatesCreate Template
POST /mailgun/v3/{domain_name}/templates
Content-Type: application/x-www-form-urlencoded
name=my-template&description=Welcome email&template=<html><body>Hello {{name}}</body></html>Get Template
GET /mailgun/v3/{domain_name}/templates/{template_name}Delete Template
DELETE /mailgun/v3/{domain_name}/templates/{template_name}List Mailing Lists
GET /mailgun/v3/lists/pagesCreate Mailing List
POST /mailgun/v3/lists
Content-Type: application/x-www-form-urlencoded
address=newsletter@example.com&name=Newsletter&description=Monthly newsletter&access_level=readonlyAccess levels: readonly, members, everyone
Get Mailing List
GET /mailgun/v3/lists/{list_address}Update Mailing List
PUT /mailgun/v3/lists/{list_address}
Content-Type: application/x-www-form-urlencoded
name=Updated NewsletterDelete Mailing List
DELETE /mailgun/v3/lists/{list_address}List Members
GET /mailgun/v3/lists/{list_address}/members/pagesAdd Member
POST /mailgun/v3/lists/{list_address}/members
Content-Type: application/x-www-form-urlencoded
address=member@example.com&name=John Doe&subscribed=yesGet Member
GET /mailgun/v3/lists/{list_address}/members/{member_address}Update Member
PUT /mailgun/v3/lists/{list_address}/members/{member_address}
Content-Type: application/x-www-form-urlencoded
name=Jane Doe&subscribed=noDelete Member
DELETE /mailgun/v3/lists/{list_address}/members/{member_address}Bounces
# List bounces
GET /mailgun/v3/{domain_name}/bounces
# Add bounce
POST /mailgun/v3/{domain_name}/bounces
Content-Type: application/x-www-form-urlencoded
address=bounced@example.com&code=550&error=Mailbox not found
# Get bounce
GET /mailgun/v3/{domain_name}/bounces/{address}
# Delete bounce
DELETE /mailgun/v3/{domain_name}/bounces/{address}Unsubscribes
# List unsubscribes
GET /mailgun/v3/{domain_name}/unsubscribes
# Add unsubscribe
POST /mailgun/v3/{domain_name}/unsubscribes
Content-Type: application/x-www-form-urlencoded
address=unsubscribed@example.com&tag=*
# Delete unsubscribe
DELETE /mailgun/v3/{domain_name}/unsubscribes/{address}Complaints
# List complaints
GET /mailgun/v3/{domain_name}/complaints
# Add complaint
POST /mailgun/v3/{domain_name}/complaints
Content-Type: application/x-www-form-urlencoded
address=complainer@example.com
# Delete complaint
DELETE /mailgun/v3/{domain_name}/complaints/{address}Whitelists
# List whitelists
GET /mailgun/v3/{domain_name}/whitelists
# Add to whitelist
POST /mailgun/v3/{domain_name}/whitelists
Content-Type: application/x-www-form-urlencoded
address=allowed@example.com
# Delete from whitelist
DELETE /mailgun/v3/{domain_name}/whitelists/{address}Get Stats
GET /mailgun/v3/{domain_name}/stats/total?event=delivered&event=openedQuery parameters:
event(required) - Event type(s): accepted, delivered, failed, opened, clicked, unsubscribed, complainedstart- Start date (RFC 2822 or Unix timestamp)end- End dateresolution- Data resolution (hour, day, month)duration- Period to show stats for
List Tags
GET /mailgun/v3/{domain_name}/tagsGet Tag
GET /mailgun/v3/{domain_name}/tags/{tag_name}Delete Tag
DELETE /mailgun/v3/{domain_name}/tags/{tag_name}List IPs
GET /mailgun/v3/ipsGet IP
GET /mailgun/v3/ips/{ip_address}Get Tracking Settings
GET /mailgun/v3/domains/{domain_name}/trackingUpdate Open Tracking
PUT /mailgun/v3/domains/{domain_name}/tracking/open
Content-Type: application/x-www-form-urlencoded
active=yesUpdate Click Tracking
PUT /mailgun/v3/domains/{domain_name}/tracking/click
Content-Type: application/x-www-form-urlencoded
active=yesUpdate Unsubscribe Tracking
PUT /mailgun/v3/domains/{domain_name}/tracking/unsubscribe
Content-Type: application/x-www-form-urlencoded
active=yes&html_footer=<a href="%unsubscribe_url%">Unsubscribe</a>List Credentials
GET /mailgun/v3/domains/{domain_name}/credentialsCreate Credential
POST /mailgun/v3/domains/{domain_name}/credentials
Content-Type: application/x-www-form-urlencoded
login=alice&password=supersecretDelete Credential
DELETE /mailgun/v3/domains/{domain_name}/credentials/{login}