Skip to content

Sending Email Via MailGun SMTP

To be able to send email via MailGun SMTP you read this knowledgebase article: Where do I find my MailGun information?

Mailgun supports sending via SMTP. The servers listen on ports 25465587, and 2525. Port 465 requires a TLS connection. Ports 25587, and 2525 require a non-TLS connection but may be upgraded to TLS using the STARTTLS command.

  • Some ISPs are blocking or throttling SMTP port 25. We recommend using #587 instead.
  • Google Compute Engine allows port 2525 for SMTP submission.
  • SMTP send will error with “cannot parse to address” or “cannot parse from address” if the provided email address fails syntax checks in accordance with RFC5321, RFC5322, RFC6854.

Use “plain text” SMTP authentication and the credentials from the domain details page in your Control Panel which can be found by clicking on a domain in the Domains Tab. For enhanced security, use TLS encryption.

Passing Sending Options

When sending a message via SMTP you can pass additional sending options via custom MIME headers listed in the table below.

HeaderDescription
X-Mailgun-TagTag string used for aggregating stats. See Tagging for more information. You can mark a message with several categories by setting multiple X-Mailgun-Tag headers.
X-Mailgun-DkimEnables/disables DKIM signatures on per-message basis. Use yes or no.
X-Mailgun-Deliver-ByDesired time of delivery. See Scheduling Delivery and Date Format.
X-Mailgun-Drop-MessageEnables sending in test mode. Pass yes if needed. See Sending in Test Mode.
X-Mailgun-TrackToggles tracking on a per-message basis, see Tracking Messages for details. Pass yes or no.
X-Mailgun-Track-ClicksToggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yesno or htmlonly.
X-Mailgun-Track-OpensToggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes or no.
X-Mailgun-Require-TLSUse this header to control TLS connection settings. See TLS Sending Connection Settings
X-Mailgun-Skip-VerificationUse this header to control TLS connection settings. See TLS Sending Connection Settings
X-Mailgun-Recipient-VariablesUse this header to substitute recipient variables referenced in a batched mail message. See Batch Sending
X-Mailgun-VariablesUse this header to attach a custom JSON data to the message. See Attaching Data to Messages for more information.
X-Mailgun-Delivery-Time-Optimize-PeriodToggles STO on a per-message basis. String should be set to the number of hours in [0- 9]+h format. See Sending a message with STO for details.
X-Mailgun-Time-Zone-LocalizeToggles 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.