Email System
ShipKit uses Resend for reliable email delivery, with support for transactional emails, audience management, and delivery tracking.
Overview
The email system provides:
- Transactional email sending
- Audience management
- Email templates
- Delivery tracking
- Error handling
- Type-safe API
Core Setup
Installation
Configuration
Environment Configuration
Required environment variables:
Email Services
Feedback Email Service
Notification Service
The notification service provides a unified way to send notifications through multiple channels, including email:
Server Actions
Feedback Action
Audience Management
Email Templates
Email templates are defined using HTML with dynamic content injection:
Usage Examples
Sending Transactional Email
Managing Audience
Error Handling
The system implements comprehensive error handling:
-
Client Initialization
-
Service Errors
-
Action Errors
Development Workflow
-
Local Development
- Use test API key
- Log emails instead of sending
- Monitor email queue
-
Testing
- Mock Resend client
- Verify email content
- Test error scenarios
-
Production
- Use production API key
- Monitor delivery rates
- Track bounces and complaints
Performance Considerations
-
Batch Processing
- Group similar emails
- Use rate limiting
- Implement retry logic
-
Template Optimization
- Cache templates
- Minimize dynamic content
- Optimize images
-
Error Recovery
- Implement backoff strategy
- Queue failed attempts
- Log delivery issues
Security Implementation
-
API Key Management
- Secure key storage
- Environment-based keys
- Regular key rotation
-
Content Security
- HTML sanitization
- Link validation
- Attachment scanning
-
Access Control
- Rate limiting
- IP allowlisting
- Audit logging
Best Practices
-
Email Content
- Use responsive design
- Test across clients
- Follow anti-spam guidelines
-
Delivery Optimization
- Set proper headers
- Include unsubscribe links
- Monitor engagement
-
Error Management
- Implement retry logic
- Log delivery issues
- Alert on failures
Notes
- Resend client is optional (null if API key not set)
- Templates use HTML with dynamic content
- Error handling is comprehensive
- Audience management is optional
- Development mode includes safety checks