Integrate
Setting up emails with Mailgun
Setup Mailgun
- Create a Mailgun account
- Follow instructions to verify your account and get setup.
Get on the Flex Plan
- Mailgun has a flex plan which allows you to use custom domains but it is hidden away.
You must sign up for the
Foundation Plan's 30 day free trial
then Unsubscribe from the trial. Flex plan charges $1 for every 1,000 emails sent, with no subscription fee.
- Mailgun has a flex plan which allows you to use custom domains but it is hidden away.
You must sign up for the
Configure DNS and SMTP
- Go to Sending->Domains and click
Add new domain
. Type in mail.yourdomain.com (i.e mail.svelteship.com is mine). Then ClickAdd Domain
- Follow these steps to verify your domain with Cloudflare.
TIPGo to the Deploy section to see how to setup Cloudflare if you do not have a cloudflare account yet.
- Go to Sending->Domain Settings->SMTP credentials. Click
Add new SMTP user
name it [email protected] and clickCreate
.
- Go to Sending->Domains and click
Add Mailgun SMTP server to Supabase
Supabase rate limits emails on their development server so we will use our newly created one from mailgun. Go to Project Settings ->Authentication. In the SMTP settings, section enter your newly created SMTP user in the
Sender email
field. ForSender name
put the name of your project/app. In the SMTP provider settings, ForHost
enter smtp.mailgun.org , Port number 465.TIPYou can customize the email templates in the Supabase Auth console to include your product name and branding.
Set Api Keys
- Go to your account and navigate to API Security
Click on [Add new key] and give it a short description. Save the value in your .env for key
PRIVATE_MAILGUN_API_KEY
. - Go to Send->Domains and either use the sandbox domain for testing, or put in your custom domain i.e
mail.yourdomain.com
Use your mailgun custom domain for sending emails to yourself or others.
You should NOT use the mailgun sandbox domain in production as it only sends emails to authorized recipients.
- Go to your account and navigate to API Security
Click on [Add new key] and give it a short description. Save the value in your .env for key
Sending emails
edit
/src/lib/server/mailgun/subscribe.ts
, and modifyfrom:
,to:
andsubject
address to the email you want mailgun to send to when people subscribe.