Email System
Our application uses Resend for sending emails and React Email for creating beautiful, responsive email templates. This guide will show you how to use both tools effectively.Architecture Overview
Setup
1. Environment Variables
Add the following to your.env file:
2. Dependencies
Creating Email Templates
Using React Email
Create your email templates in theapps/server/src/email-templates directory. Here’s an example:
Sending Emails
Using the Email Service
We provide a simple email service to send emails using Resend:Email Service Implementation
The email service is implemented inapps/server/src/services/email.ts:
Best Practices
-
Template Organization
- Keep all email templates in
apps/server/src/email-templates - Use TypeScript for type safety
- Follow a consistent naming convention
- Keep all email templates in
-
Styling
- Use inline styles for maximum email client compatibility
- Test emails across different email clients
- Keep designs simple and responsive
-
Error Handling
- Always implement proper error handling
- Log email sending failures
- Implement retry mechanisms for failed sends
-
Testing
- Test email templates in development
- Use React Email’s preview feature
- Test across different email clients
Common Use Cases
1. Email Verification
2. Password Reset
Troubleshooting
Common Issues
-
Emails Not Sending
- Check RESEND_API_KEY is correctly set
- Verify email addresses are valid
- Check Resend dashboard for delivery status
-
Styling Issues
- Use inline styles
- Test in multiple email clients
- Keep designs simple
-
Template Rendering
- Use React Email’s preview feature
- Check for TypeScript errors
- Verify all props are passed correctly