Email Service
Send emails using Resend and React Email components in your application.
This template uses Resend for email services. For more information, visit the Resend documentation.
Setup
Prerequisites
Resend Account
Verified Domain
React Email
Installation
Install the required packages:
Environment Variables
Add the following variables to your .env.local
file:
Make sure to verify your domain or email address in Resend before using it as a sender.
Implementation
Resend Client Setup
Configure the Resend client in lib/resend.ts
:
Email Template Component
Create type-safe email templates using React Email components:
React Email components make it easy to create responsive, well-designed emails that work across different email clients.
Usage Examples
Sending Emails
Example of sending an email with a React Email template:
Error Handling
Implement proper error handling when sending emails:
Available Components
Layout Components
🏗️ Html, Head, Body, Container, Section, etc.
Typography
Styling
Media
Email Templates
Magic Link Email
Authentication magic link template:
Secure login link
Encrypted, time-limited link for secure authentication
Fallback text link
Plain text URL for clients that don't support buttons
User email display
Shows the recipient's email for verification
Branded design
Maintains your application's brand identity
Welcome Email
New user onboarding email:
Personalized greeting
Custom welcome message with user's name
Getting started steps
Support information
Social links
Connect users with your social media presence
Integration with Authentication
Here's how to integrate email sending with Better-auth for magic link authentication:
Best Practices
Implementation
- Use TypeScript for type safety
- Create reusable components
- Implement proper error handling
- Test emails in development
Design
- Ensure mobile responsiveness
- Use web-safe fonts
- Include plain text fallback
- Follow email design standards
Preview and Testing
Resend provides a development mode for testing emails without actual delivery, as well as a dashboard to view sent emails.
To preview emails during development: