@felipefreitag/email-preview
v0.3.0
Published
Check email HTML/React Email for Gmail compatibility
Readme
Email Preview
Preview how your HTML and React Email templates will render in Gmail before you send them.
Gmail applies CSS transformations that can break your email design. Prevent issues without needing to manually send the email.
Overview of the building process
Features
- Dual input modes - Paste raw HTML or React Email (TSX) code
- Gmail simulation - Applies the same transformations Gmail uses
- Issue detection - Reports unsupported CSS, size limits, auto-linking
- Instant preview - See results as you type
- CLI tool - Run checks with AI agents and CI/CD pipelines
Quick Start
Editor
Visit the live app and paste your email code in the editor.
CLI
Installation
npm install -g @felipefreitag/email-preview
# or
pnpm add -g @felipefreitag/email-previewUsage
# Check a file
email-preview ./emails/welcome.html
email-preview ./emails/welcome.tsx
# Inline content
email-preview --stdin '<div style="display:flex">test</div>'
# Pipe from stdin
cat email.html | email-preview
# JSON output - for AI agents
email-preview email.html --jsonOptions
| Flag | Description |
|------|-------------|
| -f, --file <path> | Read input from file |
| --stdin | Treat argument as HTML/TSX content |
| --json | Output as JSON |
| -h, --help | Show help |
| -v, --version | Show version |
Exit Codes
| Code | Meaning |
|------|---------|
| 0 | Success - no issues, or only warnings |
| 1 | Error - issues that need attention |
| 2 | Failure - CLI error (file not found, invalid args) |
What It Checks
<style>blocks - Removed if placed in<body>(must be in<head>) or contain parse errors- CSS properties - Filters unsupported properties (flex, grid, position, etc.)
- CSS selectors - Attribute selectors not supported
- Media queries - Some query types filtered
<link>stylesheets - External CSS removed entirely- Email size - Warns if >102KB (Gmail clips content)
- Images - Detects download overlay and spacing issues
- Auto-linking - Detects URLs/emails that Gmail will convert to links
- Default font - Injects Gmail's
font-family: sans-seriffor accurate rendering
TSX Sandbox
React Email code runs in a sandboxed environment with these limits:
- Allowed imports:
@react-email/*andreactonly - Code size: 50KB maximum
- Execution timeout: 5 seconds
- No file access: Relative imports are stripped
- Tailwind: Custom configs replaced with defaults
Security
How User Code Execution Works
The TSX compiler uses Node.js vm.runInNewContext() to execute user-provided React Email code.
This does NOT provide a safe execution environment for unsafe code. There are code protections for common patterns, but more robust isolation should be prepared for a production app.
Development
# Install dependencies
pnpm install
# Start dev server
pnpm dev
# Run tests
pnpm test
# Run e2e tests
pnpm test:e2e
# Type check
pnpm typecheck
# Lint and format
pnpm lint-fixLicense
MIT
