Overview
Resend provides email delivery for AI Studio’s transactional emails:- Welcome emails for new users
- Workspace invitation emails
- Email verification links
- Password reset emails
Configuration
Environment Variables
Add the following to your.env.local file:
Setup Steps
Create Resend Account
- Sign up at resend.com
- Verify your email address
- Complete account setup
Get API Key
- Go to API Keys
- Click Create API Key
- Name: “AI Studio Production” (or “Development”)
- Permission: Sending access
- Copy the API key (starts with
re_) - Add to
.env.localasRESEND_API_KEY
Add Domain (Production)
For production, add and verify your domain:
- Go to Domains
- Click Add Domain
- Enter your domain (e.g.,
yourdomain.com) - Add the provided DNS records to your domain:
- SPF record
- DKIM record
- DMARC record (optional but recommended)
- Wait for verification (usually takes a few minutes)
For testing, you can send emails from
[email protected] without domain verification.Email Client
The Resend client is configured inlib/email.ts:
lib/email.ts
Email Functions
AI Studio includes 4 pre-built email functions:Welcome Email
Sent when a user signs up:emails/welcome-email.tsx
Invite Email
Sent when inviting users to a workspace:emails/invite-email.tsx
Verification Email
Sent for email verification:emails/verify-email.tsx
Password Reset Email
Sent when requesting a password reset:emails/reset-password-email.tsx
Email Templates
All email templates are built with React Email and stored in theemails/ directory.
Example Template Structure
emails/welcome-email.tsx
Preview Emails Locally
Use React Email’s dev server to preview templates:http://localhost:3001 showing all email templates with hot reload.
Usage Examples
In Server Actions
lib/actions/auth.ts
In API Routes
app/api/invite/route.ts
Error Handling
All email functions throw errors on failure:Best Practices
- Don’t block user actions - Send emails asynchronously
- Handle failures gracefully - Don’t fail user operations if email fails
- Use try-catch - Always wrap email calls in error handling
- Test templates - Use
pnpm emailto preview before deploying - Monitor delivery - Check Resend dashboard for delivery status
Rate Limits
Resend has the following rate limits: Free Tier:- 100 emails/day
- 3,000 emails/month
- No domain verification required for testing
- 50,000+ emails/month
- Custom sending limits
- Domain verification required
- Better deliverability
Monitoring
Resend Dashboard
Monitor email delivery in the Resend dashboard:- Delivery status (sent, delivered, bounced)
- Open rates and click rates
- Bounce and complaint tracking
- Email logs and debugging
Webhooks (Optional)
Set up webhooks to track email events:app/api/webhooks/resend/route.ts