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 for |
to required | string Email address of the recipient(s). Example: |
subject required | string Message subject |
html required | string Body of the message (HTML version) |
t:version | string Render a specific version of the given template instead of the latest version. |
cc | string Same as |
bcc | string Same as |
text | string Body of the message (text version) |
amp-html | string AMP part of the message. Please follow Google guidelines to compose and send AMP emails |
attachment | string File attachment. You can post multiple |
inline | string Attachment with |
template | string Name of a template stored via template API to use to render the email body. See Templates for more information |
o:skip-verification | string If set to |
t:text | string Pass |
t:variables | string A valid JSON-encoded dictionary used as the input for template variable expansion. See Templates for more information |
o:tag | string Tag string. See Tagging for more information |
o:dkim | string Enables/disables DKIM signatures on a per-message basis. Pass |
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 (https://mailgun-docs.redoc.ly/docs/mailgun/api-reference/intro/#date-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. |
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. Pass |
o:tracking | string Toggles both click and open tracking on a per-message basis, see Tracking Messages for details. Pass |
o:tracking-clicks | string Toggles click tracking on a per-message basis. Has higher priority than domain-level setting. Pass |
o:tracking-opens | string Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass |
o:require-tls | string If set to |
v:my-var | string
|
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:sending-ip | string Used to specify an IP Address to send an email that is owned by your account |
o:tracking-pixel-location-top | string If you send long emails that experience truncation or other rendering issues at the recipient, you can ensure opens are being tracked accurately with placement of the tracking pixel at the top of your emails |
recipient-variables | string A valid JSON-encoded dictionary, where key is a plain recipient address and value is a dictionary with variables that can be referenced in the message body. See Batch Sending for more information |
h:X-My-Header | string h: prefix followed by a Header/Value pair. For example: h:X-Mailgun-Sending-Ip-Pool=xx.xx.xxx.x. |
{- "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 | string Email address of the recipient(s). Example: |
message required | string MIME string of the message. Make sure to use |
t:variables | string A valid JSON-encoded dictionary used as the input for template variable expansion. See Templates for more information |
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 Pass |
o:tracking | string Toggles both click and open tracking on a per-message basis, see Tracking Messages for details. Pass |
o:tag | string Tag string. See Tagging for more information |
o:dkim | string Enables/disables DKIM signatures on a per-message basis. Pass |
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 (https://mailgun-docs.redoc.ly/docs/mailgun/api-reference/intro/#date-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. |
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. Pass |
o:sending-ip | string Used to specify an IP Address to send an email that is owned by your account |
o:tracking-clicks | string Toggles click tracking on a per-message basis. Has higher priority than domain-level setting. Pass |
o:tracking-opens | string Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass |
o:require-tls | string If set to |
o:skip-verification | string If set to |
v:my-var | string
|
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 If you send long emails that experience truncation or other rendering issues at the recipient, you can ensure opens are being tracked accurately with placement of the tracking pixel at the top of your emails |
h:X-My-Header | string h: prefix followed by a Header/Value pair. For example: h:X-Mailgun-Sending-Ip-Pool=xx.xx.xxx.x. |
recipient-variables | string A valid JSON-encoded dictionary, where key is a plain recipient address and value is a dictionary with variables that can be referenced in the message body. See Batch Sending for more information |
{- "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
A 400 response
A 404 response
{- "stripped-html": "<html>This is some html</html>",
- "To": "cool.barr@cool.com, bar.baz@gmail.com",
- "Mime-Version": "1.0",
- "From": "foo.bar@my-domain.com",
- "body-plain": "This is some html",
- "X-Mailgun-Template-Variables": "{\"name\":\"Foo\",\"phrase\":\"Bar\"}",
- "stripped-text": "This is some html",
- "from": "foo.bar@my-domain.com",
- "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",
- "universe"
], - [
- "Message-Id",
- "<xxxxxxxxxxxxx.111111111111111@my-domain.com>"
], - [
- "Content-Transfer-Encoding",
- "7bit"
], - [
- "Content-Type",
- "text/html; charset=ascii"
]
], - "Subject": "\"Mailgun is awesome\"",
- "Message-Id": "<xxxxxxxxxxxxx.111111111111111@my-domain.com>",
- "Content-Transfer-Encoding": "7bit",
- "X-Mailgun-Tag": "earth",
- "Content-Type": "text/html; charset=ascii",
- "subject": "\"Mailgun is awesome\"",
- "sender": "foo.bar@my-domain.com",
- "recipients": "cool.barr@cool.com, bar.baz@gmail.com",
- "body-html": "<html>This is some html</html>",
- "X-Mailgun-Template-Name": "my-awesome-template"
}
Provides default and scheduled message queue information.
A 200 response
required | object |
required | object |
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"
}
}
}
Deletes all scheduled and undelivered mail from the domain queue. This endpoint must be called on the storage API host and in the domain's region. 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"
}