Set up email preview and testing in development
✓Works with OpenClaudeYou are an email developer setting up local email preview and testing infrastructure. The user wants to set up email preview and testing in development so they can view rendered emails before sending them to real recipients.
What to check first
- Verify Node.js version:
node --version(need v14+) - Check if
nodemaileris installed:npm list nodemailer - Confirm you have a test email account or local SMTP service ready
Steps
- Install
nodemailerandnodemailer-mockfor testing:npm install nodemailer nodemailer-mock - Install
mailhogormailtrapCLI tool for catching emails locally:npm install --save-dev mailhog(or use Docker:docker run -p 1025:1025 -p 8025:8025 mailhog/mailhog) - Create a
mail.config.jsfile to define SMTP transport configuration with environment-based settings - Set up a dedicated email service module that uses
nodemailer.createTransport()with your preview service credentials - Create test email templates using
ejsorhandlebars:npm install ejs - Build a preview route (e.g.,
/preview-email) that renders templates without sending - Configure
.env.developmentwithMAIL_HOST=localhostandMAIL_PORT=1025for local testing - Test the complete flow by triggering an email send and verifying it appears in the preview UI
Code
// mail.config.js
const nodemailer = require('nodemailer');
const path = require('path');
const fs = require('fs');
const ejs = require('ejs');
const isDevelopment = process.env.NODE_ENV === 'development';
// Create transporter based on environment
const createTransporter = () => {
if (isDevelopment) {
return nodemailer.createTransport({
host: process.env.MAIL_HOST || 'localhost',
port: process.env.MAIL_PORT || 1025,
secure: false,
auth: false
});
}
return nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
});
};
// Email service with preview capability
class EmailService {
constructor() {
this.transporter = createTransporter();
this.templatesDir = path.join(__dirname, 'templates');
}
async renderTemplate(templateName, data) {
const templatePath = path.join(this.templatesDir, `${templateName}.ejs`);
const template = fs.readFileSync(templatePath, 'utf-8');
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Email Skills
Other Claude Code skills in the same category — free to download.
React Email
Build beautiful emails with React Email components
MJML Templates
Create responsive email templates with MJML
Transactional Email
Build transactional email system with Resend or SendGrid
Email Queue
Queue and batch email sending for reliability
Email Unsubscribe
Implement email preference center and unsubscribe handling
Email Deliverability Audit
Audit your email setup (SPF, DKIM, DMARC, BIMI) to maximize inbox placement
Email Template Design
Build email templates that render correctly in Gmail, Outlook, and Apple Mail
Want a Email skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.