Skip to content

Send an email in MIME format

Request

Build a MIME string yourself using a MIME library and submit it to Mailgun. Important: Send options (parameters starting with o:, h:, v:, or t:) are limited to 16KB total

Security
basicAuth
Path
domain_namestringrequired

Domain name used to send the message

Bodymultipart/form-datarequired
toArray of stringsrequired

Email address of the recipient(s). Supports friendly name format. Example: "Bob <bob@host.com>". Use commas to separate multiple recipients. Duplicate addresses are automatically ignored.

messagestring, (binary)required

MIME string of the message. Make sure to use multipart/form-data content type to send this as a file upload

templatestring

Name of a template stored via template API to use to render the email body. See Templates for more information

t:versionstring

Render a specific version of the given template instead of the latest version. template option must also be provided.

t:textstring

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.

ValueDescription
yes

Render template in the text part of the message

t:variablesstring

A valid JSON-encoded dictionary used as the input for template variable expansion. See Templates for more information

o:tagArray of strings

Tag string. See Tags for more information

o:dkimstring

Enables or disables DKIM signatures on a per-message basis. Overrides the domain-level DKIM setting for this specific message.

Enum ValueDescription
yes

Enables DKIM signatures

no

Disable DKIM signatures

true

Enables DKIM signatures

false

Disable DKIM signatures

o:secondary-dkimstring

Specify a second domain key to sign the email with. The value is formatted as signing_domain/selector, e.g. example.com/s1. This tells Mailgun to sign the message with the signing domain example.com using the selector s1. Note: the domain key specified must have been previously created and activated.

o:secondary-dkim-publicstring

Specify an alias of the domain key specified in o:secondary-dkim. Also formatted as public_signing_domain/selector. o:secondary-dkim option must also be provided. Mailgun will sign the message with the provided key of the secondary DKIM, but use the public secondary DKIM name and selector. Note: We will perform a DNS check prior to signing the message to ensure the public keys matches the secondary DKIM.

o:deliverytimestring

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:deliver-withinstring

Specifies the maximum time window for delivering the message. Accepts values in format [0-9]+h[0-9]+m (e.g., 1h30m, 30m, 24h), with a minimum of 5m and maximum of 24h. For scheduled messages, the delivery window starts from the scheduled time. The standard retry schedule applies within this window, so shorter timeframes may result in fewer delivery attempts.

o:deliverytime-optimize-periodstring

Toggles Send Time Optimization (STO) on a per-message basis. String should be set to the number of hours in [0-9]+h format, with the minimum being 24h and the maximum being 72h. This value defines the time window in which Mailgun will run the optimization algorithm based on prior engagement data of a given recipient. See Sending a Message with STO for details. Please note that STO is only available on certain plans. See www.mailgun.com/pricing for more info

o:time-zone-localizestring

Toggles Timezone Optimization (TZO) on a per message basis. String should be set to preferred delivery time in HH:mm or hh:mmaa format, where HH:mm is used for 24 hour format without AM/PM and hh:mmaa is used for 12 hour format with AM/PM. See Sending a Message with TZO for details. Please note that TZO is only available on certain plans. See www.mailgun.com/pricing for more info

o:testmodestring

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

ValueDescription
yes

Send in test mode

o:trackingstring

Toggles both click and open tracking on a per-message basis, see Tracking Messages for details.

Enum ValueDescription
yes

Enable tracking on a per-message basis

no

Disable tracking on a per-message basis

true

Enable tracking on a per-message basis

false

Disable tracking on a per-message basis

htmlonly

Use if you only want links rewritten in the HTML part of the message

o:tracking-clicksstring

Toggles click tracking on a per-message basis, see Tracking Clicks. This overrides the domain-level click tracking setting

Enum ValueDescription
yes

Enable tracking on a per-message basis

no

Disable tracking on a per-message basis

true

Enable tracking on a per-message basis

false

Disable tracking on a per-message basis

htmlonly

Use if you only want links rewritten in the HTML part of the message

o:tracking-opensstring

Toggles opens tracking on a per-message basis, see Tracking Opens. Has higher priority than domain-level setting.

Enum ValueDescription
yes

Enables opens tracking

no

Disable opens tracking

true

Enables opens tracking

false

Disable opens tracking

o:require-tlsstring

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.

Enum ValueDescription
yes

Message only be sent over a TLS connection

no

Message do not require to be sent over a TLS connection

true

Message only be sent over a TLS connection

false

Message do not require to be sent over a TLS connection

o:skip-verificationstring

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.

Enum ValueDescription
yes

Verification skipped

no

Verification active

true

Verification skipped

false

Verification active

o:sending-ipstring

Used to specify an IP Address to send an email that is owned by your account

o:sending-ip-poolstring

If an IP Pool ID is provided, the email will be delivered with an IP that belongs in that pool

o:tracking-pixel-location-topstring

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.

Enum ValueDescription
yes

Enables tracking

no

Disable tracking

true

Enables tracking

false

Disable tracking

htmlonly

Use if you only want links rewritten in the HTML part of the message

o:archive-tostring

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-headersstring

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.

o:inbox-placement-test-keystring

Triggers an Inbox Placement test for this message using the provided value as an idempotency key. Retried or duplicate send requests that use the same key will not create additional tests. Requires Inbox Placement to be enabled for your account.

h:X-My-Headerstring

Adds custom headers to the email. Use 'h:' prefix followed by header name and value. Example: 'h:X-Custom-Header=my-value'

v:my-varstring

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'.NOTE: Anything over 4KB will be truncated in the event/webhooks

recipient-variablesstring

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*anyadditional property
curl -i -X POST \
  -u '<username>:<password>' \
  'https://api.mailgun.net/v3/{domain_name}/messages.mime' \
  -H 'Content-Type: multipart/form-data' \
  -F 'to=["string"]' \
  -F message=string \
  -F template=string \
  -F t:version=string \
  -F t:text=yes \
  -F t:variables=string \
  -F 'o:tag=["string"]' \
  -F o:dkim=yes \
  -F o:secondary-dkim=string \
  -F o:secondary-dkim-public=string \
  -F o:deliverytime=string \
  -F o:deliver-within=string \
  -F o:deliverytime-optimize-period=string \
  -F o:time-zone-localize=string \
  -F o:testmode=yes \
  -F o:tracking=yes \
  -F o:tracking-clicks=yes \
  -F o:tracking-opens=yes \
  -F o:require-tls=yes \
  -F o:skip-verification=yes \
  -F o:sending-ip=string \
  -F o:sending-ip-pool=string \
  -F o:tracking-pixel-location-top=yes \
  -F o:archive-to=string \
  -F o:suppress-headers=string \
  -F o:inbox-placement-test-key=string \
  -F h:X-My-Header=string \
  -F v:my-var=string \
  -F recipient-variables=string

Responses

A 200 response

Bodyapplication/json
idstringrequired

The unique identifier of the message as defined by RFC-2392.

messagestringrequired

A success message

Response
{ "id": "message-id", "message": "Queued. Thank you." }