Mailgun silently removed their "pay-as-you-go" flex tier from their pricing page, but it's still there.

Start a free trial for the $35 tier, then cancel it. You'll be downgraded to the "pay-as-you-go" free tier. If you send <1000 emails/mo you'll pay $1/mo.

Prefer to use Resend? Here's a tutorial made by Bill Nalen.


  • Create a new account on Mailgun
  • In [Sending] click [Domains] then [Add New Domain]. It's recommended to add a subdomain like
  • If you pick the EU region, add the URL below to the Mailgun client setup in /libs/mailgun.ts right under username: "api": like this:


    1url: ""
  • Do all the DNS verification steps. If you use a subdomain, make sure it's reflected in your DNS records.
  • Add extra DMARC for better deliverability: TXT | | v=DMARC1; p=none
  • Go to [Domain Settings] then [SMTP Credentials] then [Reset Password], choose [Automatic] and then [Create Password]
  • Click [Copy] at the bottom right of the modal. In .env.local, set EMAIL_SERVER without the brackets to:
  • .env.local


    or if you picked EU region then set EMAIL_SERVER without the brackets to:


  • In [Sending API Keys] click [Create sending key] and add it to .env.local as MAILGUN_API_KEY
  • (skip if do not need to receive emails)
    • In [Receiving] click [Create Route].
    • Select [Match Recipient] and add the email you want to send from. (i.e. Make sure to match the email you set up at mailgun.supportEmail in the config.ts file.
    • Forward to https://[your-domain].com/api/webhook/mailgun.
    • Click [Create Route].
    • Then add your receiving email (I use my Gmail for instance) in mailgun.forwardREpliesTo in the config.ts file.

Check your records are valid on MxToolbox (enter your subdomain if you used one)

Sending Emails

There are 2 ways to send emails:

  • SMTP - Emails sent for magic login links will be sent using SMTP, for instance.
  • Mailgun API - To send any other emails, use the sendEmail() function in /libs/mailgun.ts.

Receiving Emails

Mailgun doesn't forward emails automatically, nor store them.

So we created a route that match emails sent to our support email (mailgun.supportEmail in config.ts) and forward them to our API ( which forwards them to our forwardRepliesTo email in config.ts file.

It automatically adds the sender in reply-to so you can reply directly from your inbox.

Avoid Spam Folder Checklist

  • Send for a subdomain (

  • Add a SPF Record (in subdomain)

  • Add a DKIM Record (in subdomain)

  • Add a DMARC Record (in subdomain)

  • Add an unsubscribe link at the bottom

  • Personalise email with recipient name

  • Avoid spam trigger words like free or earn money

  • Avoid uncommon fonts, weird layout or extreme punctuation

  • Avoid links to non-reputable websites