The email templates feature allows users to create, manage, and reuse email templates for their campaigns, providing a streamlined way to maintain consistent branding and messaging.
Features
Template Management
- Create Templates: Design custom email templates with HTML and plain text versions
- Edit Templates: Modify existing templates with real-time preview
- View Templates: Preview how templates will look to recipients
- Delete Templates: Remove unwanted templates with confirmation
- Duplicate Templates: Create copies of existing templates for variation
Template Content
- HTML Content: Rich HTML email content with full styling support
- Plain Text: Optional plain text version for accessibility
- Variable Substitution: Dynamic content using template variables
- Subject Lines: Customizable subject lines with variable support
Template Organization
- Default Template: Set one template as default for new campaigns
- Search & Filter: Find templates by name or subject
- Template Library: Organized view of all user templates
- Creation Date: Track when templates were created and last modified
Preview & Testing
- Live Preview: Real-time preview while editing
- Email Client Simulation: See how emails will render
- Variable Preview: Preview with sample data
- Responsive Design: Templates work across email clients
Technical Implementation
Database Schema
The emailTemplates
table stores:
- Template metadata (name, subject, creation dates)
- HTML and plain text content
- Default template status
- User association via
createdByClerk
File Structure
app/dashboard/studio/templates/ ├── page.tsx # Templates listing page ├── new/ │ └── page.tsx # Create new template └── [id]/ ├── page.tsx # View template └── edit/ └── page.tsx # Edit template
Template Variables
Available variables for dynamic content:
{{firstName}}
- Contact's first name{{lastName}}
- Contact's last name{{email}}
- Contact's email address{{company}}
- Contact's company{{unsubscribeUrl}}
- Unsubscribe link
Default Template
A comprehensive HTML template is provided with:
- Responsive design
- Professional styling
- Variable placeholders
- Unsubscribe link
- Best practices implementation
API Endpoints
Queries
getUserEmailTemplates
- Get all templates for a usergetEmailTemplate
- Get specific template by IDgetDefaultTemplate
- Get user's default template
Mutations
createEmailTemplate
- Create new templateupdateEmailTemplate
- Update existing templatedeleteEmailTemplate
- Remove templateduplicateEmailTemplate
- Copy existing template
Security Features
Access Control
- Users can only access their own templates
- Template ownership verification on all operations
- Secure template ID validation
Data Validation
- Required field validation (name, subject, HTML content)
- Content sanitization for XSS prevention
- Input length limits for performance
Usage Workflow
Creating a Template
- Navigate to Dashboard → Studio → Templates
- Click "New Template"
- Fill in template name and subject
- Design HTML content (default template provided)
- Optional: Add plain text version
- Optional: Set as default template
- Preview and save
Managing Templates
- View all templates in organized grid
- Search templates by name or subject
- Quick actions: View, Edit, Duplicate, Delete
- Set default template with star indicator
- Track creation and modification dates
Using Templates
- Templates integrate with campaign creation
- Default template auto-loads in new campaigns
- Variables automatically replaced with contact data
- HTML and plain text versions sent appropriately
Best Practices
Email Design
- Use inline CSS for better email client compatibility
- Keep subject lines under 50 characters
- Always include plain text version
- Test across multiple email clients
- Include unsubscribe link for compliance
Template Organization
- Use descriptive names for easy identification
- Set appropriate default template
- Regular cleanup of unused templates
- Version control through duplication
Content Guidelines
- Personalize with template variables
- Maintain consistent branding
- Clear call-to-action buttons
- Mobile-responsive design
- Accessible content structure
Integration Points
Campaign Creation
Templates integrate seamlessly with the campaign system:
- Auto-load default template in new campaigns
- Template picker for campaign creation
- Variable substitution during send
- Template metrics and performance tracking
Branding System
Templates work with the branding feature:
- Company logo integration
- Brand color consistency
- Automated branding application
- Corporate identity maintenance
Future Enhancements
Planned Features
- Template Categories: Organize templates by type/purpose
- Shared Templates: Team template sharing capabilities
- Template Analytics: Track template usage and performance
- A/B Testing: Split test different template versions
- Template Marketplace: Pre-built professional templates
- Visual Editor: Drag-and-drop template builder
- Template Export/Import: Backup and share templates
The email templates feature provides a robust foundation for professional email marketing campaigns with enterprise-level functionality and user-friendly management.