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

waveorb-mailer

v0.2.1

Published

Waveorb email client with support for templates and layouts

Downloads

10

Readme

Waveorb Mailer

Send emails with Waveorb. Boasts the following features:

  • Send email with mxmail
  • Layout support
  • Supports HTML, Markdown and Mustache templates
  • Automatically converts HTML to use as text version

Made for the Waveorb web app development platform.

Installation

npm i waveorb-mailer

Templates

In app/layouts add a file called mail.js:

module.exports = async function(mail, $, data) {
  return /* html */`
    <!doctype html>
    <html lang="en">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>${mail.subject || 'Waveorb Mailer'}</title>
        <style>
          body { background-color: gold; }
        </style>
      </head>
      <body>
        <div class="content">${mail.content}</div>
        <div>Best regards</div>
      </body>
    </html>
  `
}

Then in your app/mail directory add a file called mail1.js (or whatever):

module.exports = async function($, data) {
  return {
    layout: 'mail',
    subject: 'mail1',
    content: `mail1 html content link ${data.key}`
  }
}

The email content can be written in Markdown:

// ...
format: 'markdown',
content: `# Hello`
// ...

The layout can't do Markdown, it has to be HTML.

You can use the file option to set the content from a file:

module.exports = async function($, data) {
  return {
    layout: 'mail',
    subject: 'mail1',
    file: 'data/markdown/mail.md'
  }
}

The markdown will be automatically transformed to HTML if it's a markdown file.

Variables

You can pass variables through the data parameter:

await mailer.send('mail1', $, options, data)
// ...
content: `mail1 html content link ${data.key}`
// ...

You can also use Mustache:

// ...
content: `mail1 html content link {{data.key}}`
// ...

Both of these techniques work in the layout as well.

Configuration

If you don't provide a config file emails will be sent through mx record lookup.

To use your own email server to send mail, create a file called mail.yml in app/config:

host: smtp.ethereal.email
port: 587
auth:
  user: [email protected]
  pass: 1md9Xes49Nbfka6aFw

Create a plugin in app/plugins called mailer.js:

const mailer = require('waveorb-mailer')

module.exports = async function(app) {
  app.mailer = mailer(app.config.mail)
}

Send email

Emails will automatically include the text version which is converted from the HTML in your templates.

// Use mailer from plugin
const mailer = $.app.mailer

// Send email
const options = {
  to: 'Vidar Eldøy <[email protected]>',
  attachment: [file]
}

// All possible options:
{
  to: '[email protected]',
  from: '[email protected]',
  cc: '[email protected]',
  bcc: '[email protected]',
  subject: 'hello',
  html: '<h1>Hello</h1>',
  text: 'Hello',
  replyTo: '[email protected]',
  attachment: [readStream]
}

// Parameters: name, $, options, data
const data = { key: 'hello' }
const result = await mailer.send('mail1', $, options, data)

// Returns delivered and failed emails
{
  delivered: [{ result, mail }],
  failed: [{ result, mail }]
}

MIT licensed. Enjoy!