npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@eropple/rx-mailer

v0.2.1

Published

TypeScript email templater and mailer built around JSX and React.

Downloads

6

Readme

@eropple/rx-mailer

npm version

@eropple/rx-mailer is a light, TypeScript-friendly email sender based around a TypeScript port of react-html-email. It uses nodemailer as its SMTP transport.

I wrote this library as the core of a replacement for @nest-modules/mailer because, in trying to work with it, I found it way too opinionated and way too hard to retrofit into it a React-based email templater in a type-safe way. Older systems are accustomed to the idea of "templates" as being separate languages, like Pug or Handlebars, that follow their own rules; with JSX, templating is first-class.

It's also type-safe.

I like type-safe.

So let's get started.

Installation

You'll need to install react, prop-types, and react-dom to use this library, as @eropple/rx-mailer treats them as peer dependencies.

npm install --save @eropple/rx-mailer react prop-types react-dom
yarn add @eropple/rx-mailer react prop-types react-dom

Usage

This is a pretty thin glue wrapper around react-dom and nodemailer, so deep introspection should be left for those libraries. Here's the quickest possible starting point for you, though (lifted from the E2E test, which right now just tests for basic functionality and not for deep correctness):

import React from 'react'; // necessary if you're using JSX

import { Mailer, Email, Box, Span } from '../src';

const rnd = Math.round(Math.random() * 5000).toString().padStart(4, '0');
const mailer = new Mailer({
  nodemailer: {
    transport: 'smtp://localhost:24025',
    defaults: {
      from: `"[${rnd}] RxMailer Test" <rx-mailer-${rnd}@example.com>`,
    },
  },
});

await mailer.sendEmail({
    subject: `[${rnd}] Test email`,
    to: `recipient-${rnd}@example.org`,
    html: <Email
      title={`[${rnd}] Test Email`}
    >
      <p>
        Hello, <Span style={{ fontWeight: 'bold', color: '#ff0000' }}>world</Span>!
      </p>
      <p>
        This is a test email.
      </p>
      <p>
        Sincerely,<br />
        Ed
      </p>
    </Email>,
  });

Components

(This section lifted in its entirety from react-html-email Any discrepancies are my fault and not those of the original creator; my TypeScript port may not be perfect. Feel free to file an issue if that's the case!)

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

As with react-html-email, you can pass a string prop headCSS to your <Email> component. You can see it in react-html-email's kitchenSink.jsx example.

Running Tests

You'll need to start up docker-compose file in the repository to run the tests.

Special Thanks