You don't have to use Mailgun, but you'll need an email tool to to setup magic login links, abandoned carts emails, etc...
- Create a new account on Mailgun
- In [Sending] click [Domains] then [Add New Domain]. It's recommended to add a subdomain like mail.yourdomain.com
- 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:
- Go to [Domain Settings] then [SMTP Credentials] then [Reset Passsword], choose [Automatic] and then [Create Password]
- Click [Copy] at the bottom right of the modal. In .env.local, set
smtp://postmaster@[mail.yourdomain.com]:[copied_password]@smtp.mailgun.org:587(without the brackets)
- In [Sending API Keys] click [Create sending key] and add it to .env.local as
- (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. firstname.lastname@example.org). Make sure to match the email you set up at mailgun.supportEmail in the config.js file.
https://[your-domain].com/api/webhook/mailgun. Click [Create Route].
Then add your receiving email (I use my gmail for instance) in
There are 2 ways to send emails:
1/ SMTP: Emails sent for magic login links will be sent using SMTP, for instance.
2/ Mailgun API: To send any other emails, use the sendEmai() function in libs/mailgun.js.
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.js) and forward them to our API (your-domain.com/api/webhook/mailgun) which forwards them to our forwardRepliesTo email in config.js.
It automatically adds the sender in reply-to so you can reply directly from your inbox.