Configuration
Learn how to configure Resend and set up email sending.
The starter kit uses Resend for sending emails. Resend is a modern email API designed for developers, offering excellent deliverability and a simple integration.
Setup
1. Create a Resend Account
- Go to Resend and create an account
- Navigate to the API Keys section in your dashboard
- Click Create API Key
- Give it a name (e.g., "Production" or "Development")
- Copy the API key (starts with
re_)
2. Configure Environment Variables
Add the following environment variables to your .env file:
RESEND_API_KEY=re_...
EMAIL_FROM=noreply@yourdomain.comSecurity Note
Never commit your API keys to version control. Always use environment
variables and ensure .env is in your .gitignore.
3. Domain Setup
To send emails from your own domain:
-
Go to Domains in your Resend dashboard
-
Click Add Domain
-
Enter your domain (e.g.,
yourdomain.com) -
Add the required DNS records to verify your domain:
- SPF Record - Authorizes Resend to send emails
- DKIM Record - Signs emails for authentication
- DMARC Record (optional) - Email authentication policy
-
Wait for domain verification (usually a few minutes)
-
Update
EMAIL_FROMto use your verified domain:
EMAIL_FROM=noreply@yourdomain.comUsing Resend's Domain
For testing, you can use Resend's default domain:
onboarding@resend.dev. However, for production, always use your
own verified domain for better deliverability.
Email Functions
The email functions in lib/email automatically use your environment variables.
Basic Usage
import { sendEmail } from '@/lib/email';
await sendEmail({
recipient: 'user@example.com',
subject: 'Welcome!',
html: '<h1>Welcome to our platform!</h1>',
text: 'Welcome to our platform!'
});Using Pre-built Templates
The email module exports functions for all pre-built templates:
import { sendVerifyEmailAddressEmail } from '@/lib/email';
await sendVerifyEmailAddressEmail({
recipient: user.email,
name: user.name,
verificationLink: `${getBaseUrl()}/verify-email?token=${token}`
});Retry Logic
The email service includes automatic retry logic with exponential backoff:
- Max Attempts: 3 retries
- Base Delay: 1 second
- Max Delay: 10 seconds
- Exponential Backoff: Delay doubles with each retry
Permanent errors (invalid email, auth failure) are not retried.
Error Handling
The email functions handle errors gracefully:
import { sendEmail } from '@/lib/email';
try {
await sendEmail({
recipient: 'user@example.com',
subject: 'Test',
html: '<p>Test</p>',
text: 'Test'
});
} catch (error) {
// Error is logged automatically
// Permanent errors are not retried
// Transient errors are retried automatically
}Production Configuration
For production deployments:
- Use a verified domain - Always use your own domain, not Resend's default
- Set up SPF/DKIM - Ensure DNS records are properly configured
- Monitor deliverability - Check Resend dashboard for bounce rates
- Set up webhooks (optional) - Track email events (delivered, bounced, etc.)
Environment Variables in Production
Add your environment variables in your hosting platform:
- Vercel: Project Settings → Environment Variables
- Railway: Variables tab
- Other platforms: Follow their environment variable documentation
Testing
Development
For local development, you can:
- Use Resend's test domain:
onboarding@resend.dev - Check the Resend dashboard for sent emails
- Use React Email Preview (see Email Templates)
Testing Emails
import { sendVerifyEmailAddressEmail } from '@/lib/email';
// Test sending an email
await sendVerifyEmailAddressEmail({
recipient: 'test@example.com',
name: 'Test User',
verificationLink: 'https://example.com/verify?token=test'
});Rate Limits
Resend has the following rate limits:
- Free Tier: 3,000 emails/month, 100 emails/day
- Pro Tier: 50,000 emails/month, higher daily limits
- Enterprise: Custom limits
Monitor your usage in the Resend dashboard to avoid hitting limits.
Best Practices
- Always use your own domain - Better deliverability and branding
- Set up DNS records correctly - SPF, DKIM and DMARC
- Monitor bounce rates - Remove invalid email addresses
- Use templates - Consistent branding and easier maintenance
- Handle errors gracefully - Log errors and notify admins
- Test before production - Verify emails look correct across clients