• Stars
    star
    895
  • Rank 51,027 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create elegant HTML email templates using React.

react-html-email

⚠️ Currently Unmaintained

react-html-email is presently unmaintained. As React has matured, it is no longer as necessary to use a separate library to generate email-specific markup. I'd encourage you to look at more recent CSS-in-JS and style inlining component libraries as the basis for building your own email design system, though these components can serve as a useful starting point.

I think the future of this project would be a generic set of design components for email templates -- something akin to Chakra UI for email. If you'd be interested in taking ownership of this project and tackling that, drop me a line at [email protected].


Build Status Coverage Status npm npm

Modern HTML emails are a tangle of archaic HTML and inline styles. This library encapsulates the cruft into simple React components and helps avoid common pitfalls.

react-html-email provides a set of components for a standard 600px table layout (inspired by HTML Email Boilerplate). React's Supported Tags and Attributes are extended to include a few deprecated attributes useful for legacy clients. In addition, a style prop validator is included which uses Campaign Monitor's CSS Support Guide to check for potential compatibility issues across email clients.

Installation

$ npm install react-html-email

Usage

To render a simple email:

import { Email, Item, Span, A, renderEmail } from 'react-html-email'

const emailHTML = renderEmail(
  <Email title="Hello World!">
    <Item align="center">
      <Span fontSize={20}>
        This is an example email made with:
        <A href="https://github.com/chromakode/react-html-email">react-html-email</A>.
      </Span>
    </Item>
  </Email>
)

You can find more examples in the examples directory of the repo.

API

renderEmail(emailComponent)

Render an email component to an HTML string. Adds an XHTML 1.0 Strict doctype, as per HTML Email Boilerplate.

configStyleValidator(config)

By default, inline styles passed to the style prop will be validated against Campaign Monitor's CSS Support Guide. Here are the default settings, which can be overridden using configStyleValidator:

ReactHTMLEmail.configStyleValidator({
  // When strict, incompatible style properties will result in an error.
  strict: true,

  // Whether to warn when compatibility notes for a style property exist.
  warn: true,

  // Platforms to consider for compatibility checks.
  platforms: [
    'gmail',
    'gmail-android',
    'apple-mail',
    'apple-ios',
    'yahoo-mail',
    'outlook',
    'outlook-legacy',
    'outlook-web',
  ],
})

PropTypes.style

A PropTypes validator for checking email inline style compatibility. Used by default in the components below. Exported for use in your own components.

Components

Components in react-html-email include defaults for basic style properties, so that client styles are reset and normalized. Every component accepts a style prop which overrides the reset styles.

<Email>

An HTML document with a centered 600px <table> inside <table> container based on HTML Email Boilerplate.

It's necessary to always include a title prop for some clients' "open in browser" feature.

See MailChimp's HTML guide for how this works.

<Box>

A simplification of the <table> element, the workhorse of an HTML email design. <Box>es contain a vertical stack of <Item>s. Use them to create visual structure, filled buttons, and spacing.

<Item>

A subsection of a <Box>, essentially a <tr><td> unit.

<Span>

Use to assign styles to text.

It can be handy to create an object containing your default text styles for reuse. For example:

const textDefaults = {
  fontFamily: 'Verdana',
  fontSize: 42,
  fontWeight: 'bold',
  color: 'orange',
}

[...]

<Span {...textDefaults}>Congratulations!</Span>
<Span {...textDefaults}>You won a free cruise!</Span>

<A>

Use to format links. Requires an href prop. Always sets target="_blank" and defaults to underline. To remove the underline, set textDecoration="none".

<Image>

An image, without any pesky borders, outlines, or underlines by default. Requires a src prop, and width and height to be set. You can override the default styles (such as adding a border) using the style prop.

Head CSS and Media Queries

You can pass a string prop headCSS to your <Email> component. You can see it in our kitchenSink.jsx example.

Mailchimp attributes

If you're using Mailchimp and need to add their custom mc:edit attributes to your markup, we recommend using the mailchimpify module.

License

MIT

More Repositories

1

xkcdfools

xkcd CLI + jQuery terminal implementation
JavaScript
563
star
2

isolated-core

Seamless in-page cold updates using iframes.
JavaScript
211
star
3

picnic

Be spontaneous. Have a picnic!
JavaScript
173
star
4

xkcd-pixels

The frontend code behind "Pixels".
JavaScript
149
star
5

been

Life stream collector.
Python
125
star
6

pow

An experimental HTML5 presentation tool.
JavaScript
80
star
7

wake

A simple life stream web frontend to been.
Python
77
star
8

coalesce

Edit audio at the speed of text
TypeScript
42
star
9

karmabot

A highly extensible IRC karma+information bot written in Python.
Python
37
star
10

time-thief

A calm, habit-forming offline journal.
TypeScript
30
star
11

shine

a Chrome extension for reddit.
JavaScript
22
star
12

socialite

a Firefox extension for reddit social news sites.
JavaScript
18
star
13

redditron

Markov chain analysis of reddit comments
Python
17
star
14

reddit-sidebar-updater

a Google Apps Script to update your subreddit sidebar
JavaScript
16
star
15

diablo

yo-yo.js, with added components
JavaScript
15
star
16

k5

v5 of
JavaScript
15
star
17

time

A serial art project of interactive seekable animations.
JavaScript
11
star
18

bicyclejs-talk

🚲 A talk about Web Bluetooth and cyclejs @ jsconf.is
JavaScript
11
star
19

jam

An unfinished web audio live coding experiment.
JavaScript
10
star
20

conductor

A learning playlist generation engine in Python.
Python
7
star
21

blog

blah blah blah
MDX
6
star
22

exactly

A tiny wrapper around npm to shrinkwrap by content hash
JavaScript
6
star
23

imgurfox

A Firefox extension to upload images to imgur.com.
JavaScript
6
star
24

live

Real-time presentation synchronization across multiple devices in node.
JavaScript
6
star
25

havoc

Haskell Chess AI
Haskell
6
star
26

fcurve

JS port of Blender's animation bezier curve evaluator
JavaScript
6
star
27

wtfcnn

Breadpig project (http://breadpig.com/category/projects/wtfcnn/): A website to compare news websites.
JavaScript
6
star
28

ivy

A minimalistic hierarchical pubsub server with persistent event logs.
Go
5
star
29

srtfan

Take a single SRT stream and fan it out to multiple SRT callers
Go
5
star
30

josie

Old-school Python text adventure game engine.
Python
4
star
31

myo-scripts

Script / hacks / experiments with the Myo controller.
4
star
32

lookatallofus

sonder:
4
star
33

twine

A collaborative audio looper for the web.
JavaScript
4
star
34

danceparty

An animated gif dance club.
JavaScript
4
star
35

linux-vm-tools

Tools I use for developing with VMs.
Python
4
star
36

multicopter

NodeCopter multiboxing
JavaScript
3
star
37

typesetters-son

Utility for generating images of lightly modified webpages
JavaScript
3
star
38

zefram

An isomorphic app core.
JavaScript
3
star
39

synthruary

#synthruary
TypeScript
2
star
40

morphdeck

Beautiful animated slide decks using SVG and JS
JavaScript
2
star
41

skirmish

Python wrapper script to connect to Internet Mini Chess Servers
Python
1
star
42

reshape

My daily art journal from 2006 - 2007, restored for the 2023 web.
Astro
1
star
43

spanner

Chat for hackers.
JavaScript
1
star
44

simple-xkcd-viewer

A bare-bones xkcd viewer.
JavaScript
1
star
45

reddit-extralife-utils

quick and dirty scripts for our Extra Life marathon
Python
1
star
46

grace

say grace, automatically
JavaScript
1
star
47

node-simple-cert

Automatically fetch and renew an SSL certificate using Let's Encrypt
JavaScript
1
star
48

BlankSpaces

A song and drum machine for WaffleJS by Andrew and Max
HTML
1
star
49

phoenix

A pretty fast reddit mobile web frontend.
JavaScript
1
star