Skip to content

Mailgun

Mailgun works with pg_relay through the SMTP transport, using the SMTP credentials Mailgun issues per sending domain.

Why not the Mailgun REST API?

Mailgun's messages API takes its request as form-encoded fields (multipart/form-data), not as a JSON body — and the webhook transport sends message as JSON, always. The SMTP endpoint reaches the same sending domains, suppression handling, and analytics, so the SMTP path is the right one here.

Profile

{
  "host": "smtp.mailgun.org",                 // EU-region domains: smtp.eu.mailgun.org
  "port": 587,
  "security": "starttls",
  "auth": "plain",
  "username": "[email protected]", // the sending domain's SMTP login
  "password": "_env:MAILGUN_SMTP_PASSWORD",
  "from": "[email protected]",
  "timeout_seconds": 30
}
  • Hostsmtp.mailgun.org for US-region domains, smtp.eu.mailgun.org for EU-region ones; the region is a property of the sending domain in Mailgun, so match it. Port 465 with security: tls and port 2525 are also available.
  • Credentials — each Mailgun sending domain has its own SMTP credentials (the default login is postmaster@<your-sending-domain>), managed under Domain settings → SMTP credentials. The password is set or reset there — it is not your Mailgun account password, and not an API key.
  • from — an address on the verified sending domain the credentials belong to.

Message

The standard message block, exactly as the SMTP chapter describes it.

Things Mailgun enforces

  • Domain verification. The sending domain must have its DNS records (SPF and DKIM) verified in Mailgun before it will relay mail; an unverified domain's sends are rejected with a 5xx — permanent, no retry.
  • Suppression lists. Mailgun maintains per-domain bounce, unsubscribe, and complaint lists. A recipient on one is refused at RCPT TO — reported by pg_relay as a permanent failure naming the recipient by category and position, never by address.

Continue to SMTP2GO.