jsx-email
repository·main·Indexed 22 days ago
https://github.com/shellscape/jsx-emailA React and TypeScript-based framework for building responsive, high-quality email templates. It provides a specialized component library to abstract email client rendering inconsistencies and includes a CLI tool, create-mail, for project scaffolding. The framework is provider-agnostic and supports integrations with AWS SES, Loops, Nodemailer, Postmark, Resend, Plunk, and SendGrid. It features a plugin system for CSS inlining, HTML minification, cleaning unused CSS, and URL modification.
What's inside jsx-email
- JSX email is a library that provides React components and helpers for building responsive email templates using React and TypeScript. It is designed to handle the complexities of email client compatibility and cross-client inconsistencies, allowing developers to focus on template design and impact rather than low-level email rendering quirks.
Key features of JSX email
mainJSX email includes several features designed to improve developer experience and template reliability:
- Email Client Compatibility Checking: Verify how templates render across different clients via the CLI.
- Exclusive Components: Specialized components designed for email.
- Cross-client Inconsistency Handling: Automatically manages differences between email clients.
- Tailwind Support: Fast integration with Tailwind CSS.
- Async Components: Support for
<Suspense>andasyncwithin components. - Developer Experience: Includes a smooth Preview Server and powerful Command Line tools.
- Extensibility: Supports plugins and optional configuration files.
- Flexible Deployment: Works with monorepos out of the box and has no vendor lock-in.
Configure Avatar image fallbacks
mainThe
Avatarcomponent handles missing images using a specific fallback hierarchy:Visible Fallback Text Order:
- The trimmed value of the
fallbackprop. - Initials derived from the
nameprop. - The literal character
"?".
Accessibility (Alt Text) Order:
- Non-decorative avatars (
decorative={false}): Uses the order:altprop $\rightarrow$nameprop $\rightarrow$ resolved visible fallback text. - Decorative avatars (
decorative={true}): Renders withrole="presentation"andaria-hidden="true".
- The trimmed value of the
Tailwind plugin compatibility and UnoCSS
mainThe
Tailwindcomponent is not compatible with standard Tailwind Plugins out of the box because it uses UnoCSS as its engine.Instead of Tailwind plugins, you should use equivalent UnoCSS presets, Community Presets, or Transformers. If you require a specific Tailwind plugin, you may need to port it to an UnoCSS preset.
Use Plugins for rendering pipelines in v2
mainjsx-emailv2 introduces a plugin system that allows you to hook into different stages of the rendering process (before, during, or after core rendering). This is ideal for tasks like:- Minification
- CSS inlining
- Prettifying output
Core functionality for minifying and prettifying has been moved to separate plugins. This allows for smaller bundles and is particularly useful in restricted environments like Cloudflare Workers.
Understand the v2 Preview rendering changes
mainThe v2 Preview app has moved from runtime rendering to a pre-rendering model. This makes the preview faster and more reliable by removing Vite-related dependency and optimization issues. A watcher is used to provide immediate updates when templates change.
Breaking Change: Local, relative imports of assets (such as images) within templates are currently not supported due to the new rendering pipeline.
New Capability: You can now exclude specific files from being shown in the preview app.
Use the compile API to support CSS imports
mainIf you are using the
jsx-emailAPI instead of the CLI and need to support CSS imports, you cannot use therendermethod directly on a file that contains CSS imports. Instead, you must use thecompileAPI first.Workflow:
- Use the
compileAPI to process the file. - Import the resulting
Templatefrom the compiled output. - Pass that
Templateto therendermethod.
- Use the
Integrate JSX email with email providers
mainTo use JSX email with any provider, you must first transform your JSX/TSX template into HTML (and optionally plain text) using therendermethod fromjsx-email. Once rendered, pass the resulting HTML string to your provider's SDK or API. This allows you to use JSX email with virtually any service that accepts a string for content input.Important considerations when using Inline CSS
mainWhile inlining CSS improves compatibility, it significantly increases the byte size of the email HTML.
Warning: Email Clipping Email clients like Gmail will clip emails that exceed certain size limits, forcing recipients to click a "Show Full Message" button.
Best Practice Monitor your console output when running the
rendermethod;jsx-emailwill alert you if the resulting HTML size is too large.Integrate JSX email with email service providers
mainJSX email is provider-agnostic. Since it renders emails as strings, you can use it with any email service provider that accepts a string payload via an API.
Supported integrations include:
- AWS SES
- Loops
- Nodemailer
- Postmark
- Resend
- Plunk
- SendGrid
Install the JSX email URL Plugin
mainInstall the plugin via npm:
npm install @jsx-email/plugin-urlUse the JSX email URL Plugin
mainThe
@jsx-email/plugin-urlplugin modifies URLs within the rendered email HTML. Its primary feature is theappendoption, which allows you to automatically append specific URL parameters to matching URL attributes in your email templates.Note: This plugin is not loaded automatically by
jsx-email. You must manually add it to thepluginsarray in your configuration.