Architecture
The email system uses a mailer abstraction that automatically selects the best available provider:src/lib/messaging/email/mailer.ts
The system automatically falls back to console logging if no provider is configured, making development easier.
Supported Providers
Resend
Modern email API with excellent deliverability (recommended)
Postmark
Transactional email service with detailed analytics
Plunk
Simple email API for developers
Nodemailer
SMTP support for any email provider
Provider Priority
IfEMAIL_PROVIDER is not set, the system auto-discovers providers in this order:
- Custom (if injected via
setCustomEmailProvider) - Resend (if
RESEND_API_KEYis set) - Postmark (if
POSTMARK_API_KEYis set) - Plunk (if
PLUNK_API_KEYis set) - Nodemailer (if SMTP credentials are set)
- Log (console fallback for development)
Configuration
- Resend
- Postmark
- Plunk
- Nodemailer (SMTP)
.env
Resend is the recommended provider for ShipFree due to its simplicity and reliability.
Sending Emails
The email system provides a simple API for sending emails:Basic Usage
With React Email Templates
1
Create Email Template
Email templates are located in
src/components/emails/:src/components/emails/auth/welcome-email.tsx
2
Render Template
Use the render function to convert React components to HTML:
src/components/emails/render.ts
3
Send Email
Email Types
ShipFree distinguishes between two email types:- Transactional
- Marketing
Transactional emails are triggered by user actions and contain critical information:
- Password reset emails
- Email verification
- Order confirmations
- Account notifications
Transactional emails do not include unsubscribe links and should only be used for essential communications.
Built-in Email Templates
ShipFree includes pre-built email templates for authentication flows:Welcome Email
Sent after email verification
Password Reset
Secure password reset flow
OTP Verification
One-time password codes
Example: OTP Email
src/lib/auth/auth.ts
Batch Emails
Send multiple emails efficiently:Email Validation
Validate email addresses before sending:Server-Side Usage
- Server Component
- API Route
- Server Action
src/app/(auth)/verify/page.tsx
Check Email Service Status
Attachments
Send files with emails:Reply-To Headers
Custom Provider
Inject a custom email provider at runtime:Error Handling
The email system provides detailed error information:Development Mode
Without any email provider configured, emails are logged to the console:Best Practices
Use Templates
Always use React Email templates for consistent branding
Validate First
Validate email addresses before sending to reduce bounces
Handle Errors
Always check send results and implement retry logic
Respect Privacy
Include unsubscribe links for marketing emails
Further Reading
React Email
Build beautiful emails with React components
Resend Docs
Resend API documentation
Postmark Docs
Postmark developer guides
Email Best Practices
Learn about email deliverability