Skip to main content
ShipFree includes a provider-agnostic email system that supports multiple email services through a unified interface. Send transactional emails, marketing campaigns, and more with automatic provider fallback.

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

If EMAIL_PROVIDER is not set, the system auto-discovers providers in this order:
  1. Custom (if injected via setCustomEmailProvider)
  2. Resend (if RESEND_API_KEY is set)
  3. Postmark (if POSTMARK_API_KEY is set)
  4. Plunk (if PLUNK_API_KEY is set)
  5. Nodemailer (if SMTP credentials are set)
  6. Log (console fallback for development)

Configuration

.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 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:
If the provider supports native batch sending (like Resend), it will be used automatically. Otherwise, emails are sent sequentially.

Email Validation

Validate email addresses before sending:

Server-Side Usage

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:
Always check the success property before assuming an email was sent successfully.

Development Mode

Without any email provider configured, emails are logged to the console:
This makes it easy to test authentication flows locally without setting up an email provider.

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