Send email two ways via our REST API:
Reminder: You can also send email via SMTP with Mailgun. Please reference the user manual.
Pass the components of the messages such as To, From, Subject, HTML and text parts, attachments, etc. Mailgun will build a MIME representation of the message and send it. Note: In order to send you must provide one of the following parameters: 'text', 'html', 'amp-html' or 'template'
from required | string Email address of the | ||||||||||||
to required | Array of strings Email address of the recipient(s). Supports friendly name format. Example: | ||||||||||||
subject required | string Message subject. Note: not required if sending with a template that has a pre-set Subject header, but it will override it if provided. | ||||||||||||
cc | Array of strings Same as | ||||||||||||
bcc | Array of strings Same as | ||||||||||||
text | string Body of the message (text version) | ||||||||||||
html | string Body of the message (HTML version) | ||||||||||||
amp-html | string AMP part of the message. Please follow Google guidelines to compose and send AMP emails | ||||||||||||
attachment | Array of strings <binary> File attachment. You can post multiple | ||||||||||||
inline | Array of strings <binary> Attachment with | ||||||||||||
template | string Name of a template stored via the Templates API to use to render the email body. See Templates for more information | ||||||||||||
t:version | string Render a specific version of the given template instead of the latest version. | ||||||||||||
t:text | string Generates a plain text version of the template alongside the HTML version when sending templated emails. When set to 'yes', instructs Mailgun to create a text/plain MIME part based on the template content, ensuring compatibility with email clients that don't support HTML or have HTML rendering disabled. This improves email deliverability and accessibility by providing a fallback text version in multipart emails.
| ||||||||||||
t:variables | string A valid JSON-encoded dictionary used as the input for template variable expansion. See Templates for more information | ||||||||||||
o:tag | Array of strings Tag string. See Tagging for more information | ||||||||||||
o:dkim | string Enables or disables DKIM signatures on a per-message basis. Overrides the domain-level DKIM setting for this specific message.
| ||||||||||||
o:secondary-dkim | string Specify a second domain key to sign the email with. The value is formatted as | ||||||||||||
o:secondary-dkim-public | string Specify an alias of the domain key specified in | ||||||||||||
o:deliverytime | string Specifies the scheduled delivery time in RFC-2822 format. Depending on your plan, you can schedule messages up to 3 or 7 days in advance. If your domain has a custom message_ttl (time-to-live) setting, this value determines the maximum scheduling duration. Example: 'Fri, 14 Oct 2011 12:00:00 +0000' | ||||||||||||
o:deliverytime-optimize-period | string Toggles Send Time Optimization (STO) on a per-message basis. String should be set to the number of hours in | ||||||||||||
o:time-zone-localize | string Toggles Timezone Optimization (TZO) on a per message basis. String should be set to preferred delivery time in | ||||||||||||
o:testmode | string Enables sending in test mode. Messages are processed normally but not actually delivered to recipients. Useful for testing without sending real emails. See Sending in Test Mode
| ||||||||||||
o:tracking | string Toggles both click and open tracking on a per-message basis
| ||||||||||||
o:tracking-clicks | string Toggles click tracking on a per-message basis, see Tracking Clicks. This overrides the domain-level click tracking setting.
| ||||||||||||
o:tracking-opens | string Toggles opens tracking on a per-message basis, see Tracking Opens. Has higher priority than domain-level setting.
| ||||||||||||
o:require-tls | string When set to 'yes', requires the message to be sent only over a TLS connection to the Email Service Provider. If TLS cannot be established, the message will not be delivered. When set to 'no' (default), Mailgun attempts TLS but falls back to plaintext SMTP if needed.
| ||||||||||||
o:skip-verification | string If
| ||||||||||||
o:sending-ip | string Used to specify an IP Address to send an email that is owned by your account | ||||||||||||
o:sending-ip-pool | string If an IP Pool ID is provided, the email will be delivered with an IP that belongs in that pool | ||||||||||||
o:tracking-pixel-location-top | string Places the tracking pixel at the top of emails instead of the bottom. Useful for long emails that may be truncated or have rendering issues, ensuring open tracking works accurately.
| ||||||||||||
o:archive-to | string Sends a copy of successfully delivered messages to the specified URL via HTTP POST. The request uses Content-Type: application/mime and contains the exact message the recipient's SMTP server received. NOTE: These are accounted for and billed as delivered messages | ||||||||||||
o:suppress-headers | string Removes specified X-Mailgun headers from the delivered message. Provide header names separated by commas (e.g., 'X-Mailgun-Variables,X-Mailgun-Tag') or use 'all' to remove all X-Mailgun headers.Note: X-Mailgun-Sid header is currently used to process complains received via feedback loops. | ||||||||||||
h:X-My-Header | string Adds custom headers to the email. Use 'h:' prefix followed by header name and value. Example: 'h:X-Custom-Header=my-value' | ||||||||||||
v:my-var | string Attaches custom data to the message using the 'v:' prefix followed by a variable name. When sending with templates, provides values for template variable substitution (overridden by 't:variables' if both are provided). When not using templates, treated as metadata and included in events/webhooks. Variables are visible in the delivered email's X-Mailgun-Variables header. Example: 'v:user-id=123'. | ||||||||||||
recipient-variables | string A JSON-encoded dictionary for batch sending with personalized variables per recipient. Each key is a recipient email address, each value is a dictionary of variables for that recipient. Variables can be referenced in the message using %recipient.variablename%. Example: '{"alice@example.com": {"name":"Alice", "id":1}, "bob@example.com": {"name":"Bob", "id":2}}'. Maximum 1,000 recipients per batch. See Batch Sending for more information | ||||||||||||
property name* additional property | any |
A 200 response
id required | string The unique identifier of the message as defined by RFC-2392. |
message required | string A success message |
A 400 response
A 401 response
A 429 response
A 500 response
{- "id": "message-id",
- "message": "Queued. Thank you."
}
Build a MIME string yourself using a MIME library for your programming language and submit it to Mailgun.
to required | Array of strings Email address of the recipient(s). Supports friendly name format. Example: | ||||||||||||
message required | string <binary> MIME string of the message. Make sure to use | ||||||||||||
template | string Name of a template stored via template API to use to render the email body. See Templates for more information | ||||||||||||
t:version | string Render a specific version of the given template instead of the latest version. | ||||||||||||
t:text | string Generates a plain text version of the template alongside the HTML version when sending templated emails. When set to 'yes', instructs Mailgun to create a text/plain MIME part based on the template content, ensuring compatibility with email clients that don't support HTML or have HTML rendering disabled. This improves email deliverability and accessibility by providing a fallback text version in multipart emails.
| ||||||||||||
t:variables | string A valid JSON-encoded dictionary used as the input for template variable expansion. See Templates for more information | ||||||||||||
o:tag | Array of strings Tag string. See Tags for more information | ||||||||||||
o:dkim | string Enables or disables DKIM signatures on a per-message basis. Overrides the domain-level DKIM setting for this specific message.
| ||||||||||||
o:secondary-dkim | string Specify a second domain key to sign the email with. The value is formatted as | ||||||||||||
o:secondary-dkim-public | string Specify an alias of the domain key specified in | ||||||||||||
o:deliverytime | string Specifies the scheduled delivery time in RFC-2822 format. Depending on your plan, you can schedule messages up to 3 or 7 days in advance. If your domain has a custom message_ttl (time-to-live) setting, this value determines the maximum scheduling duration. Example: 'Fri, 14 Oct 2011 12:00:00 +0000' | ||||||||||||
o:deliverytime-optimize-period | string Toggles Send Time Optimization (STO) on a per-message basis. String should be set to the number of hours in | ||||||||||||
o:time-zone-localize | string Toggles Timezone Optimization (TZO) on a per message basis. String should be set to preferred delivery time in | ||||||||||||
o:testmode | string Enables sending in test mode. Messages are processed normally but not actually delivered to recipients. Useful for testing without sending real emails. See Sending in Test Mode
| ||||||||||||
o:tracking | string Toggles both click and open tracking on a per-message basis, see Tracking Messages for details.
| ||||||||||||
o:tracking-clicks | string Toggles click tracking on a per-message basis, see Tracking Clicks. This overrides the domain-level click tracking setting
| ||||||||||||
o:tracking-opens | string Toggles opens tracking on a per-message basis, see Tracking Opens. Has higher priority than domain-level setting.
| ||||||||||||
o:require-tls | string When set to 'yes', requires the message to be sent only over a TLS connection. If TLS cannot be established, the message will not be delivered. When set to 'no' (default), Mailgun attempts TLS but falls back to plaintext SMTP if needed.
| ||||||||||||
o:skip-verification | string When set to 'true', skips certificate and hostname verification for TLS connections. When 'false' (default), Mailgun verifies certificates and hostnames - if verification fails, TLS connection is not established.
| ||||||||||||
o:sending-ip | string Used to specify an IP Address to send an email that is owned by your account | ||||||||||||
o:sending-ip-pool | string If an IP Pool ID is provided, the email will be delivered with an IP that belongs in that pool | ||||||||||||
o:tracking-pixel-location-top | string Places the tracking pixel at the top of emails instead of the bottom. Useful for long emails that may be truncated or have rendering issues, ensuring open tracking works accurately.
| ||||||||||||
o:archive-to | string Sends a copy of successfully delivered messages to the specified URL via HTTP POST. The request uses Content-Type: application/mime and contains the exact message the recipient's SMTP server received. NOTE: These are accounted for and billed as delivered messages | ||||||||||||
o:suppress-headers | string Removes specified X-Mailgun headers from the delivered message. Provide header names separated by commas (e.g., 'X-Mailgun-Variables,X-Mailgun-Tag') or use 'all' to remove all X-Mailgun headers.Note: X-Mailgun-Sid header is currently used to process complains received via feedback loops. | ||||||||||||
h:X-My-Header | string Adds custom headers to the email. Use 'h:' prefix followed by header name and value. Example: 'h:X-Custom-Header=my-value' | ||||||||||||
v:my-var | string Attaches custom data to the message using the 'v:' prefix followed by a variable name. When sending with templates, provides values for template variable substitution (overridden by 't:variables' if both are provided). When not using templates, treated as metadata and included in events/webhooks. Variables are visible in the delivered email's X-Mailgun-Variables header. Example: 'v:user-id=123'. | ||||||||||||
recipient-variables | string A JSON-encoded dictionary for batch sending with personalized variables per recipient. Each key is a recipient email address, each value is a dictionary of variables for that recipient. Variables can be referenced in the message using %recipient.variablename%. Example: '{"alice@example.com": {"name":"Alice", "id":1}, "bob@example.com": {"name":"Bob", "id":2}}'. Maximum 1,000 recipients per batch. See Batch Sending for more information. | ||||||||||||
property name* additional property | any |
A 200 response
id required | string The unique identifier of the message as defined by RFC-2392. |
message required | string A success message |
A 400 response
A 401 response
A 429 response
A 500 response
{- "id": "message-id",
- "message": "Queued. Thank you."
}
Event(s) created from sending an email with Mailgun will contain a storage.key
to use to retrieve the email.
A 200 response
Content-Transfer-Encoding required | string The content transfer encoding if enabled |
Content-Type required | string The content type sent with the message with a possible boundary |
From required | string The full 'From' email address entry of the email |
Message-Id required | string The unique identifier of the message as defined by RFC-2392 |
Mime-Version required | string The MIME version of the email |
Subject required | string Subject of the email |
To required | string The full 'To' email address entries |
X-Mailgun-Tag required | string The raw tags of the message if provided |
sender required | string Just the email address from the provided 'From'' field |
recipients required | string A list of email addresses from the 'To'' field |
body-html required | string The full HTML body of the full message |
body-plain required | string The plain text body of the full message |
stripped-html required | string Only the body of the email in HTML |
stripped-text required | string Only the body of the email in plain text |
stripped-signature required | string The signature stripped from the body |
message-headers required | Array of strings The full list of headers of the MIME upon send |
X-Mailgun-Template-Name required | string The name of the template if one was used |
X-Mailgun-Template-Variables required | string The variables used in the template if one was used |
A 400 response
A 404 response
{- "Content-Transfer-Encoding": "7bit",
- "Content-Type": "multipart/form-data; boundary=----SomeFormBoundaryABC123",
- "From": "foo.bar@my-domain.com",
- "Message-Id": "<xxxxxxxxxxxxx.111111111111111@my-domain.com>",
- "Mime-Version": "1.0",
- "Subject": "\"Mailgun is awesome\"",
- "To": "Cool Bar <cool.barr@cool.com>, bar.baz@gmail.com",
- "X-Mailgun-Tag": "Earth",
- "sender": "foo.bar@my-domain.com",
- "recipients": "cool.barr@cool.com, bar.baz@gmail.com",
- "body-html": "<html>This is some html</html>",
- "body-plain": "This is some html",
- "stripped-html": "<html>This is some html</html>",
- "stripped-text": "This is some html",
- "stripped-signature": "the signature block stripped from the plain text message (if found)",
- "message-headers": [
- [
- "Mime-Version",
- "1.0"
], - [
- "Subject",
- "\"Mailgun is awesome\""
], - [
- "From",
- "foo.bar@my-domain.com"
], - [
- "To",
- "cool.barr@cool.com, bar.baz@gmail.com"
], - [
- "X-Mailgun-Tag",
- "Earth"
], - [
- "Message-Id",
- "<xxxxxxxxxxxxx.111111111111111@my-domain.com>"
], - [
- "Content-Transfer-Encoding",
- "7bit"
], - [
- "Content-Type",
- "text/html; charset=ascii"
]
], - "X-Mailgun-Template-Name": "my-awesome-template",
- "X-Mailgun-Template-Variables": "{\"name\":\"Foo\",\"phrase\":\"Bar\"}"
}
Provides default and scheduled message queue information.
A 200 response
required | object Message queue response |
required | object Scheduled message queue response |
A 401 response
A 404 response
{- "regular": {
- "is_disabled": true,
- "disabled": {
- "until": "Mon, 02 Jan 2006 15:04:05 MST",
- "reason": "You have too many messages in queue"
}
}, - "scheduled": {
- "is_disabled": true,
- "disabled": {
- "until": "Mon, 02 Jan 2006 15:04:05 MST",
- "reason": "You have too many messages in queue"
}
}
}
Deletes all scheduled and undelivered mail from the domain queue. This endpoint must be called on the same storage API host as the mail's generated storage URL. e.g. https://storage-us-east4.api.mailgun.net/v3/example.com/envelopes
The storage hosts are: storage-us-east4.api.mailgun.net
, storage-us-west1.api.mailgun.net
, and storage-europe-west1.api.mailgun.net
.
{- "message": "done"
}