How to hit the Mailgun API

Mailgun's API lives at https://api.mailgun.net/v3 (api.eu.mailgun.net for EU accounts). Sending is a form POST to your domain.

Authentication

Mailgun uses Basic auth with the literal username api and your API key as the password — curl's -u, PostTaco's Auth tab. Find the key under API Security. In the examples it's written {{MAILGUN_API_KEY}}; {{MAILGUN_DOMAIN}} is your sending domain.

Full reference: https://documentation.mailgun.com/docs/mailgun/api-reference/

Send an email

curl -X POST https://api.mailgun.net/v3/{{MAILGUN_DOMAIN}}/messages \
  -u api:{{MAILGUN_API_KEY}} \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "from=PostTaco <postmaster@{{MAILGUN_DOMAIN}}>" \
  -d "to={{TO_EMAIL}}" \
  -d "subject=Hello from PostTaco" \
  -d "text=It works."
Run in PostTaco

Recent events

Deliveries, opens, bounces, and failures.

curl "https://api.mailgun.net/v3/{{MAILGUN_DOMAIN}}/events?limit=10" \
  -u api:{{MAILGUN_API_KEY}}
Run in PostTaco

List domains

curl https://api.mailgun.net/v4/domains \
  -u api:{{MAILGUN_API_KEY}}
Run in PostTaco