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 | Array of strings Email address of the recipient(s). Example: | ||||||||||||
subject required | string Message subject | ||||||||||||
html required | string Body of the message (HTML version) | ||||||||||||
cc | Array of strings Same as | ||||||||||||
bcc | Array of strings 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 | 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 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 Render template in case of template sending
| ||||||||||||
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/disables DKIM signatures on a per-message basis
| ||||||||||||
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://documentation.mailgun.com/docs/mailgun/user-manual/get-started/#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 | |||||||||||||
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. Has higher priority than domain-level 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 Requires the message only be sent over a TLS connection, see TLS Sending Connection Settings. If a TLS connection can not be established, Mailgun will not deliver the message. If set to
| ||||||||||||
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 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. | ||||||||||||
v:my-var | string
| ||||||||||||
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 | ||||||||||||
property name* additional property | any |
{- "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). 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 Render template in the text part of the message in case of template sending
| ||||||||||||
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/disables DKIM signatures on a per-message basis
| ||||||||||||
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 | |||||||||||||
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. Has higher priority than domain-level 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 Requires the message only be sent over a TLS connection, see TLS Sending Connection Settings. If a TLS connection can not be established, Mailgun will not deliver the message. If set to
| ||||||||||||
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 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. | ||||||||||||
v:my-var | string
| ||||||||||||
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 | ||||||||||||
property name* additional property | any |
{- "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
{- "Content-Transfer-Encoding": "7bit",
- "Content-Type": "text/html; charset=ascii",
- "From": "foo.bar@my-domain.com",
- "Message-Id": "<xxxxxxxxxxxxx.111111111111111@my-domain.com>",
- "Mime-Version": "1.0",
- "Subject": "\"Mailgun is awesome\"",
- "To": "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",
- "from": "foo.bar@my-domain.com",
- "subject": "\"Mailgun is awesome\"",
- "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 |
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"
}
}, - "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 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"
}