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

@uscreen.de/postal-mailer

v0.6.16

Published

Mailer engine using mjml templates to send mail via postal api or smtp

Downloads

51

Readme

postal-mailer

Test CI Test Coverage Known Vulnerabilities NPM Version

Mailer engine using mjml templates to send mail via postal api or smtp

Features

  • configure inline (json object) or by dotenv
  • uses handlebars + mjml for compilation and render
  • sends mails via postal api or smtp

Install

$ yarn add @uscreen.de/postal-mailer # or use npm -i

Example

const mailer = require('@uscreen.de/postal-mailer')({
  // load config defaults from .env file (defaults to false)
  useDotenv: true,

  // override with inline options if needed
  postalSender: '[email protected]'
})

const result = await mailer
  .sendMail({
    data,
    template: 'test',
    to: '[email protected]',
    subject: 'Example Test Mail'
  })
  .then(r => {
    console.log('RESULT:', r)
  })
  .catch(e => {
    console.error('ERROR sending mail:', e)
  })

Template

Please refer to https://mjml.io and https://handlebarsjs.com. Start with example like so:

<mjml>
  <mj-head>
    <mj-title>Test Mail</mj-title>
    <mj-attributes>
      <mj-all font-family="BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;"></mj-all>
      <mj-text font-weight="300" font-size="16px" color="#000000" line-height="24px"></mj-text>
    </mj-attributes>
  </mj-head>

  <mj-body background-color="#F2F2F2">

    <mj-section background-color="#ff781e" padding="20px">
      <mj-column width="100%">
        <mj-text align="center" font-size="24px" color="#ffffff" font-weight="600">
          A very simple Test E-Mail
        </mj-text>
      </mj-column>
    </mj-section>

    <mj-section background-color="#FFFFFF" padding="40px 20px">
      <mj-column width="100%">
        <mj-text>
          Greetings {{user.firstName}} {{user.lastName}},<br>
          <br>
          this is a simple example on how to setup a template and pass in some data.
        </mj-text>
        <mj-text>
          template will prefix all asset urls (ie. imgages) with<br>"{{postalAssetsUrl}}"
        </mj-text>
      </mj-column>
    </mj-section>

    <mj-section padding="0px 0 20px 0">
      <mj-column>
        <mj-text align="center" color="#9B9B9B" font-size="11px">ACME Inc, Street. 1, 12345 City</mj-text>
      </mj-column>
    </mj-section>

  </mj-body>
</mjml>

which renders to something like this:

Options

All options can be managed via .env file and/or inline configuration as seen above. Overview of options:

| option | Description | Default | Example | |-------------------------|-------------------------------------------------------------------------------------------------------------|-------------------|-------------------------------------| | useDotenv | whether to also read options from .env files | false | true | | postalTransport | Send mail via Postal API or SMTP | postal | smtp | | postalServer | Postal Server Host | | postal.example.com | | postalPort | If sending via SMTP, the SMTP port | 25 | 25 | | postalUser | If sending via SMTP, the SMTP username | | acme/my-api | | postalKey | If sending via Postal API, the API Key to use. If sending via SMTP, the SMTP password | | ExAmPlE_key | | postalSender | From Address in emails | | [email protected] | | postalTemplates | path to directory containing email templates | <cwd>/templates | ./templates/mails | | postalAssetsUrl | url to prefix assets | '' | https://www.example.com/mail/assets | | postalDefaultLocale | when set, locales will default to 'en' and templates will default ./templates/en instead of ./templates | '' | 'en' |

API

mailer.sendMail({ template, data, to, subject, locale = '' })

Send a template rendered with data to a recepient with a subject. (In an optional language set by locale)

Roadmap

  • use esm (or shim with https://github.com/standard-things/esm)
  • upgrades: ◯ globby latest 11.0.4 ❯ 12.0.2 https://github.com/sindresorhus/globby#readme
  • deplrecate postalAssetsUrl as this is implementation context

Changelog

0.6.0

  • added smtp example
  • fixed pending upgrades

0.5.0

  • added support of attachments
  • added smtp transport

0.2.0

  • added (optional) multilanguage support for templates
  • added examples and docs

0.1.0

  • rendering of templates (to html + text) & sending thru api works