Skip to Content
DocsResend Email

Resend Email

Resend provides reliable transactional email delivery with React-powered templates. This module is already integrated in the template.

Overview

Resend offers modern email infrastructure with React email templates, excellent deliverability, and developer-friendly APIs.

Key Features:

  • React email templates
  • High deliverability rates
  • Custom domain support
  • Webhook support
  • Analytics and tracking
  • Template management

Getting Started

1. Get Resend API Key

  1. Sign up at resend.com 
  2. Go to “API Keys” section in your dashboard
  3. Create a new API key
  4. Copy the API key (starts with re_)

2. Add Environment Variables

Add this to your .env.local file:

RESEND_API_KEY=re_your_api_key_here

3. How It Works in the Template

The template includes pre-configured email system:

  • Email Templates: React components in emails/templates/
  • API Routes: Email sending endpoints in app/api/email/
  • Template Rendering: Server-side email rendering
  • Integration: Automatic welcome emails and notifications
  • Custom Domain: Easy setup for branded emails

4. Template Structure

emails/ ├── templates/ │ ├── welcome.tsx # Welcome email template │ └── password-reset.tsx # Password reset template app/api/email/ ├── welcome/ # Send welcome email ├── password-reset/ # Send password reset └── test/ # Test email endpoint

Email Templates

The template includes pre-built React email templates:

Welcome Email Template

// emails/templates/welcome.tsx (already implemented) interface WelcomeEmailProps { userFirstName?: string; userEmail?: string; appName?: string; dashboardUrl?: string; } export function WelcomeEmail({ userFirstName = 'User', userEmail, appName = 'Your App', dashboardUrl = 'https://yourapp.com/dashboard' }: WelcomeEmailProps) { return ( <div> <h1>Welcome to {appName}!</h1> <p>Hi {userFirstName},</p> <p>Thank you for signing up! Your account is ready.</p> <a href={dashboardUrl}>Go to Dashboard</a> </div> ); }

Password Reset Template

// emails/templates/password-reset.tsx (already implemented) interface PasswordResetEmailProps { userFirstName?: string; resetUrl: string; appName?: string; } export function PasswordResetEmail({ userFirstName = 'User', resetUrl, appName = 'Your App' }: PasswordResetEmailProps) { return ( <div> <h1>Reset Your Password</h1> <p>Hi {userFirstName},</p> <p>You requested to reset your password for {appName}.</p> <a href={resetUrl}>Reset Password</a> </div> ); }

API Endpoints

The template includes ready-to-use email APIs:

Welcome Email API

// app/api/email/welcome/route.ts (already implemented) import { Resend } from 'resend' import { WelcomeEmail } from '@/emails/templates/welcome' const resend = new Resend(process.env.RESEND_API_KEY!) export async function POST(request: Request) { const { email, firstName } = await request.json() const { data, error } = await resend.emails.send({ from: 'onboarding@yourapp.com', to: [email], subject: 'Welcome to Your App!', react: WelcomeEmail({ userFirstName: firstName, userEmail: email }), }) if (error) { return Response.json({ error: error.message }, { status: 500 }) } return Response.json({ success: true, messageId: data?.id }) }

Test Email API

// app/api/email/test/route.ts (already implemented) export async function POST(request: Request) { const { email } = await request.json() const { data, error } = await resend.emails.send({ from: 'test@yourapp.com', to: [email], subject: 'Test Email', html: '<p>This is a test email to verify your setup!</p>', }) return Response.json({ success: !error, messageId: data?.id }) }

Integration Examples

Send Welcome Email After Signup

The template automatically sends welcome emails:

// In your signup flow (already integrated) // This happens automatically when users sign up through authentication // Or manually trigger welcome email: await fetch('/api/email/welcome', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: user.email, firstName: user.firstName }) })

Send Password Reset Email

// For password reset functionality const sendPasswordReset = async (email: string, resetToken: string) => { const resetUrl = `${process.env.NEXT_PUBLIC_APP_URL}/reset-password?token=${resetToken}` await fetch('/api/email/password-reset', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, resetUrl, firstName: user.firstName }) }) }

Custom Email Sending

// Send custom emails using Resend directly import { Resend } from 'resend' const resend = new Resend(process.env.RESEND_API_KEY!) export async function sendCustomEmail(to: string, subject: string, content: string) { const { data, error } = await resend.emails.send({ from: 'notifications@yourapp.com', to: [to], subject, html: content, }) return { success: !error, messageId: data?.id, error } }

Custom Domain Setup

1. Add Domain in Resend

  1. Go to “Domains” in your Resend dashboard
  2. Click “Add Domain”
  3. Enter your domain (e.g., yourapp.com)

2. Configure DNS Records

Add these DNS records to your domain:

Type: MX Name: @ Value: feedback-smtp.us-east-1.amazonses.com Priority: 10 Type: TXT Name: @ Value: "v=spf1 include:amazonses.com ~all" Type: CNAME Name: resend._domainkey Value: resend._domainkey.resend.com

3. Update Email Templates

Once your domain is verified, update the from addresses:

// Use your custom domain await resend.emails.send({ from: 'noreply@yourapp.com', // Your verified domain to: [userEmail], subject: 'Welcome!', react: WelcomeEmail({ firstName }) })

Development and Testing

Testing Emails Locally

# Test email endpoint curl -X POST http://localhost:3000/api/email/test \ -H "Content-Type: application/json" \ -d '{"email": "your-email@example.com"}'

Preview Email Templates

The template includes styled email templates that render properly in email clients:

  • Responsive Design: Works on mobile and desktop
  • Inline Styles: Maximum email client compatibility
  • Professional Styling: Clean, modern appearance
  • Branded Colors: Easy to customize with your brand

Email Development Workflow

  1. Edit Templates: Modify React components in emails/templates/
  2. Test Locally: Use test API endpoint to verify rendering
  3. Deploy: Templates are automatically included in your app
  4. Monitor: Check delivery status in Resend dashboard

Advanced Features

Email with Attachments

// Add attachments to emails await resend.emails.send({ from: 'invoices@yourapp.com', to: [userEmail], subject: 'Your Invoice', react: InvoiceEmail({ invoiceNumber }), attachments: [ { filename: 'invoice.pdf', content: pdfBuffer, }, ], })

Bulk Email Sending

// Send to multiple recipients const recipients = ['user1@example.com', 'user2@example.com'] const emailPromises = recipients.map(email => resend.emails.send({ from: 'notifications@yourapp.com', to: [email], subject: 'Important Update', react: UpdateEmail({ userEmail: email }) }) ) await Promise.all(emailPromises)

Email Analytics

Resend provides analytics for:

  • Delivery rates
  • Open rates
  • Click tracking
  • Bounce management
  • Spam reports

Access these through your Resend dashboard.

Environment Configuration

Development

RESEND_API_KEY=re_test_your_api_key_here

Production

RESEND_API_KEY=re_live_your_production_key_here

Domain Configuration

For production, set up a custom domain:

  • Better deliverability
  • Professional appearance
  • Brand consistency
  • Higher trust scores

Integration with Authentication

The template automatically handles:

  • Welcome Emails: Sent when users sign up
  • Email Verification: For account activation
  • Password Reset: Secure reset links
  • Account Notifications: Status changes and updates

Clerk Integration

// The template automatically sends welcome emails when users sign up // This is handled in the user synchronization process

Supabase Integration

// For Supabase templates, emails are triggered by: // 1. User signup completion // 2. Password reset requests // 3. Account status changes

Troubleshooting

Emails not sending:

  • Check API key in environment variables
  • Verify domain status in Resend dashboard
  • Check email template syntax for errors
  • Look for rate limiting (free tier limits)

Poor deliverability:

  • Set up custom domain with proper DNS records
  • Configure SPF, DKIM records correctly
  • Avoid spam trigger words in subject lines
  • Monitor bounce and complaint rates

Templates not rendering:

  • Verify React email component syntax
  • Check for missing props or default values
  • Test with simple HTML first
  • Use inline styles for email client compatibility

Domain verification failing:

  • Double-check DNS record values
  • Allow 24-48 hours for DNS propagation
  • Verify with DNS lookup tools
  • Contact Resend support if issues persist

API endpoint errors:

  • Verify request body format
  • Check authentication headers
  • Look at server logs for detailed errors
  • Test with simple email first
Last updated on