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

@universal-packages/mailing

v1.3.4

Published

Mailing basics with modularity.

Downloads

1,808

Readme

Mailing

npm version Testing codecov

Mailing basics with modularity.

Install

npm install @universal-packages/mailing

Mailing

Mailing is the main interface for email sending, it uses an email engine and renderer to general email contents and send them over the internet.

import { Mailing } from '@universal-packages/mailing'
import { NodemailerEngine } from '@universal-packages/mailing-nodemailer'

const mailing = new Mailing( engine: 'nodemailer', engineOptions: { transport: 'smtp', options: { host: 'smtp.com'} })

await mailing.prepare()

mailing.send({ subject: 'Email', from: '[email protected]', to: '[email protected]', template: 'templates/email', locals: { name: 'Omar' } })

Options

  • engine string | EngineInterface Default: local | test Engine to use to send the email, by default if NODE_ENV is development local will be used, if NODE_ENV is test the the test engine will be used.
  • engineOptions Object Any options that the engine constructor accepts
  • renderer string | EngineInterface Default: replacer When specifying template when sending an email Mailing will use the renderer to use a template file.
  • rendererOptions Object Any options that the renderer constructor accepts
  • templatesLocation String Default: ./src Where the templates for the emails will live.

Instance methods

prepare()

Prepares engine and renderer internally.

send(sendOptions: Options)

Sends an email using the configured engine.

Options

  • bcc String | String[] Comma separated list or an array of recipients e-mail addresses that will appear on the Bcc: field.
  • cc String | String[] Comma separated list or an array of recipients e-mail addresses that will appear on the Cc: field.
  • extra Object Any extra options the engine may accept.
  • from String The e-mail address of the sender. All e-mail addresses can be plain '[email protected]' or formatted 'Sender Name [email protected]'.
  • html String The HTML version of the message.
  • locale String If provided this locale will be appended to the template name. ex templates/email.en
  • locals Object Variables to be passed to the renderer to evaluate on templates.
  • sender String An e-mail address that will appear on the Sender: field.
  • subject String The subject of the e-mail.
  • template String The name of the template without extension relative to the templatesLocation.
  • text String The plaintext version of the message.
  • text String | String[] Comma separated list or an array of recipients e-mail addresses that will appear on the To: field.

ReplacerRenderer

The replacer renderer takes templates with the html and txt extensions to fullfil the html and text options of the message.

You can pass locals when sending and this renderer will replace their values when matching {{ <local> }}

<html>
  <body>
    Hi my name is {{ name }}
  </body>
</html>

In the above example you will need to provided the local name to be replaced there in {{ name }}.

LocalEngine

The local engine instead of sending the email via internet will just open the email in the explorer.

TestEngine

The test engine is useful to mock to later expect a sending.

You will need to set the mock manually depending on the test framework you are using. For example for jest:

import { TestEngine } from '@universal-packages/mailing'

TestEngine.mock = jest.fn()

Events

Mailing will emit events as follow.

mailing.on('send:start', (event) => console.log(event))
mailing.on('send:end', (event) => console.log(event))

Typescript

This library is developed in TypeScript and shipped fully typed.

Contributing

The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.

License

MIT licensed.