Emails with Mailgun
Send beautiful transactional emails using Mailgun.
This boilerplate also supports sending transactional emails using Mailgun, a powerful email automation platform with API-based sending, reputation management, and analytics.
Mailgun Features
- API-based email sending
- Reputation management and analytics
- Domain verification and DNS configuration
- Rate limiting and abuse protection
Mailgun Setup
Step 1: Create a Mailgun Account
If you don't already have a Mailgun account, create one at mailgun.
Step 2: Add and Verify Your Domain
In your Mailgun dashboard, add your sending domain and configure the required DNS records
Mailgun will verify your DNS setup — this may take a few minutes to several hours depending on your DNS provider.
Step 3: Get Your API Key
Once you've created your account, get your API key:
- Go to the API Keys page
- Click "Add new key"
- Copy the API key
Step 3: Add API Key to Environment Variables
Add your Mailgun API key to your .env file:
EMAIL_API_KEY="..."EMAIL_FROM="Your Name <subdomain@mailgundomain>"EMAIL_SERVER_USER="SMTP login"EMAIL_SERVER_HOST="smtp.mailgun.org"EMAIL_SERVER_PORT="587"
In the subdomain, you can add your subdomain e.g. your name, update, verify, no-reply etc.
Set Rate Limiting
It's a good idea to set a sending limit in your Mailgun account to avoid misuse.
If you're just getting started or don't expect heavy traffic yet, something like 5,000 messages is a safe cap.
Go to Mailgun settings and edit the Custom Message Limit.
Email Templates
Email setup on your app
- Magic Link setup
lib/auth.ts - Login and signup page
app/login/page.tsx