Email System Setup
Configure an email provider to send automated welcome and billing emails
The email system sends automated transactional emails for user registration, billing events, and more. This guide will help you choose and configure an email provider in under 5 minutes.
What You'll Get
- Welcome emails when users sign up
- Order confirmations for new subscriptions
- Payment notifications (success/failed)
- Subscription cancellation confirmations
- Plan change notifications
- Renewal reminders (7 days before)
Choose Your Email Provider
Resend
Best for: Getting started quickly, development, and production
- Easiest setup (2 minutes)
- Free tier: 3,000 emails/month, 100 emails/day
- No domain verification needed for development
- Great developer experience
SendGrid
Best for: Enterprise-grade email delivery with advanced features
- More complex setup (5-10 minutes)
- Free tier: 100 emails/day
- Advanced analytics and reporting
- Requires domain verification
SMTP
Best for: Using your existing email server (Gmail, Mailgun, etc.)
- Use any SMTP-compatible service
- Requires SMTP credentials
- Good for self-hosted or custom setups
Get Your Email Provider API Key
Option A: Resend (Recommended)
- Go to resend.com/signup and create a free account
- Once logged in, click "API Keys" in the left sidebar
- Click "Create API Key"
- Give it a name (e.g., "Development") and click "Add"
- Copy the API key (starts with
re_)
Development Email Address
onboarding@resend.dev as your sender email without verifying a domain. For production, you'll need to add and verify your own domain.Option B: SendGrid
- Go to signup.sendgrid.com and create a free account
- Complete email verification and setup wizard
- Go to Settings â API Keys
- Click "Create API Key"
- Choose "Full Access" and give it a name
- Copy the API key (starts with
SG.)
Option C: SMTP
Get SMTP credentials from your email provider. You'll need:
- Host: SMTP server address (e.g., smtp.gmail.com)
- Port: Usually 587 (TLS) or 465 (SSL)
- Username: Your email or username
- Password: Your email password or app-specific password
Configure Environment Variables
Open your .env or .env.local file and add the following variables based on your chosen provider:
For Resend:
1EMAIL_PROVIDER=resend2EMAIL_FROM=onboarding@resend.dev3EMAIL_FROM_NAME=Your SaaS Name4RESEND_API_KEY=re_your_api_key_here5EMAIL_RETENTION_DAYS=90For SendGrid:
1EMAIL_PROVIDER=sendgrid2EMAIL_FROM=you@yourdomain.com3EMAIL_FROM_NAME=Your SaaS Name4SENDGRID_API_KEY=SG.your_api_key_here5EMAIL_RETENTION_DAYS=90For SMTP:
1EMAIL_PROVIDER=smtp2EMAIL_FROM=you@yourdomain.com3EMAIL_FROM_NAME=Your SaaS Name4SMTP_HOST=smtp.gmail.com5SMTP_PORT=5876SMTP_USER=your_email@gmail.com7SMTP_PASS=your_password_here8SMTP_SECURE=false9EMAIL_RETENTION_DAYS=90Important Notes
- Replace
Your SaaS Namewith your actual product name - For production, use a verified domain email for
EMAIL_FROM - Never commit your
.envfile to version control! EMAIL_RETENTION_DAYScontrols how long email logs are kept (default: 90 days)
Environment Variable Explained:
EMAIL_PROVIDER- Which service to use (resend, sendgrid, or smtp)EMAIL_FROM- The "from" email address that appears in emailsEMAIL_FROM_NAME- The sender name that appears in emailsRESEND_API_KEY/SENDGRID_API_KEY- Your API key from the providerEMAIL_RETENTION_DAYS- How long to keep email logs before automatic cleanup
Restart Your Development Server
For the new environment variables to take effect, you need to restart your development server.
Stop the current server:
Press Ctrl+C in the terminal where npm run dev is running.
Start it again:
1npm run devTest the Email System
The easiest way to test is to create a new user account and check for the welcome email.
- Go to
http://localhost:3000 - Click the login/sign up button
- Sign up with GitHub or Google OAuth
- Check your email for the welcome message!
Email Logging
EmailLog table). You can view them using Prisma Studio:1npm run db:studioTroubleshooting
No Email Received
If you didn't receive the welcome email:
- Check your spam/junk folder
- Verify environment variables are set correctly (no typos)
- Make sure you restarted the dev server after adding env vars
- Check the terminal for error messages
- Open Prisma Studio (
npm run db:studio) and check the EmailLog table for errors
"Email provider not configured" Error
This means the email provider environment variables are missing or incorrect.
- Check that
EMAIL_PROVIDERis set to "resend", "sendgrid", or "smtp" - Verify the corresponding API key variable is set (RESEND_API_KEY or SENDGRID_API_KEY)
- Make sure there are no extra spaces or quotes in the .env file
- Restart your dev server
Resend API Key Invalid
If you see "Invalid API key" errors:
- Double-check you copied the entire API key from Resend (starts with
re_) - Make sure there are no spaces before or after the key
- Try creating a new API key in Resend and using that instead
SendGrid "Sender Not Verified" Error
SendGrid requires domain verification for production use:
- Go to SendGrid â Settings â Sender Authentication
- Follow the domain verification process
- Update
EMAIL_FROMto use your verified domain - Alternatively, use Resend for easier development setup
SMTP Connection Failed
If SMTP connection fails:
- Verify SMTP_HOST and SMTP_PORT are correct
- For Gmail, you need an "App Password" (not your regular password)
- Check that SMTP_SECURE is set correctly (false for port 587, true for port 465)
- Some providers block SMTP - check your email provider's documentation
Production Deployment
Before deploying to production:
- Verify your domain - Most providers require domain verification for production use
- Update EMAIL_FROM - Change from
onboarding@resend.devto your verified domain - Add environment variables to your hosting platform - Vercel, Netlify, Railway, etc.
- Test thoroughly - Send test emails before launching
- Monitor email logs - Check the EmailLog table regularly for delivery issues
Resend Domain Verification
- Go to Resend â Domains â Add Domain
- Enter your domain (e.g., yourdomain.com)
- Add the provided DNS records to your domain registrar
- Wait for verification (usually 5-30 minutes)
- Update
EMAIL_FROMtono-reply@yourdomain.com
What's Next?
Your email system is now configured! To learn more about customizing email templates and understanding the automated email flow, check out the comprehensive Email System guide.