Mailgun

Mailgun

Send emails from your websites

Medium10 min0% complete

What you need

  • A Mailgun account
  • A domain you control (for custom sending address)
  1. 1.Go to Sending → Domains
  2. 2.Click "Add New Domain"
  3. 3.Enter your domain (e.g., mg.yourdomain.com)
  4. 4.Choose your region (US or EU)
  5. 5.Click "Add Domain"
💡Use a subdomain like mg.yourdomain.com to avoid issues with your main domain.
  1. 1.Mailgun will show you DNS records to add
  2. 2.Go to your DNS provider (Cloudflare, etc.)
  3. 3.Add each record exactly as shown
  4. 4.Wait a few minutes for propagation
  5. 5.Click "Verify DNS Settings" in Mailgun
⚠️DNS changes can take up to 48 hours to propagate.
  1. 1.Go to Settings → API Security
  2. 2.Copy your "Private API key"
Mailgun API Keys
# Add to your .env.local file:
MAILGUN_API_KEY=key-...
MAILGUN_DOMAIN=mg.yourdomain.com

Environment Variables

VariableDescriptionExample
MAILGUN_API_KEYYour Mailgun private API keykey-...
MAILGUN_DOMAINYour verified sending domainmg.yourdomain.com

Test Your Integration

After completing setup, try this prompt in Claude Code:

"Set up a contact form for my website that sends emails via Mailgun"