jsx-email

repository·main·Indexed 22 days ago

https://github.com/shellscape/jsx-email

A 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.

Tokens
42K
Snippets
114
Records
256
Agent score
78%

What's inside jsx-email

  1. Overview of JSX email

    main
    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.
  2. Key features of JSX email

    main

    JSX 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> and async within 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.
  3. Configure Avatar image fallbacks

    main

    The Avatar component handles missing images using a specific fallback hierarchy:

    Visible Fallback Text Order:

    1. The trimmed value of the fallback prop.
    2. Initials derived from the name prop.
    3. The literal character "?".

    Accessibility (Alt Text) Order:

    • Non-decorative avatars (decorative={false}): Uses the order: alt prop $\rightarrow$ name prop $\rightarrow$ resolved visible fallback text.
    • Decorative avatars (decorative={true}): Renders with role="presentation" and aria-hidden="true".
  4. Use Plugins for rendering pipelines in v2

    main

    jsx-email v2 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.

  5. Understand the v2 Preview rendering changes

    main

    The 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.

  6. Use the compile API to support CSS imports

    main

    If you are using the jsx-email API instead of the CLI and need to support CSS imports, you cannot use the render method directly on a file that contains CSS imports. Instead, you must use the compile API first.

    Workflow:

    1. Use the compile API to process the file.
    2. Import the resulting Template from the compiled output.
    3. Pass that Template to the render method.
  7. Integrate JSX email with email providers

    main
    To use JSX email with any provider, you must first transform your JSX/TSX template into HTML (and optionally plain text) using the render method from jsx-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.
  8. Important considerations when using Inline CSS

    main

    While 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 render method; jsx-email will alert you if the resulting HTML size is too large.

  9. Use the JSX email URL Plugin

    main

    The @jsx-email/plugin-url plugin modifies URLs within the rendered email HTML. Its primary feature is the append option, 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 the plugins array in your configuration.