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

@sapphirejs/mail

v0.0.15

Published

Fluent Mail Client for Sapphire Framework

Downloads

2

Readme

Mail

A fluent email sender built as a thin wrapper on top of nodemailer. It handles almost everything nodemailer does, but presents them in a more intuitive package. Actually supports STMP and SES transports, with plans to provide more in the future.

Usage

$ npm install --save @sapphirejs/mail

We'll start with an exhaustive example that includes pretty much every option.

const { Mail, Transport } = require('@sapphirejs/mail')

const config = { host: 'smtp.example.com' }
const mail = new Mail({}, new Transport.SMTP(config))
await mail.send('<p>Hi</p>', message => {
  message
    .from('[email protected]')
    .replyTo('[email protected]')
    .to('[email protected]')
    .cc('[email protected]')
    .bcc('[email protected]')
    .subject('Testing')
    .attach({ filename: 'file.txt', content: 'File' })
    .header('my-key', '123')
    .alternative('text/x-web-markdown', '**Email body**')
    .priority('low')
})

HTML and Text Body

The first parameter of Mail.send() can be either a string as the HTML body, or an object that may set both the text and html versions. It is a good practice to include them both.

await mail.send({ html: '<p>Hi</p>', text: 'Hi' }, /* rest of the message */)

Global "from" Header

When the "from" header is passed as Mail's config, it will be automatically included in every mail instance. Off course it also be overriden with the from function.

const mail = new Mail({ from: '[email protected]' }, new Transport.SMTP(config))

Name, Email Format

The from, replyTo, to, cc, and bcc headers can be set with a name followed by the email.

message
  .from('John Smith', '[email protected]')
  .to('Jane Smith', '[email protected]')

// or as a single parameter

message
  .from('John Smith <[email protected]>')
  .to('Jane Smith <[email protected]>')

Multiple Parameters

Multiple receivers, either to, cc, or bcc, can be chained to add more than one.

message
  .to('John Smith<[email protected]>')
  .to('Jane Smith<[email protected]>')

The same applies to header, attachment, and alternative.

Async

Mail.send() is an async function that returns a Promise and can be set to await. It will throw a MailSendingFailed if sending fails, or a MissingMailParams when the message headers aren't set correctly (ie: missing from field). Otherwise, it will return an info object with the details of the transport.

try {
  const mail = new Mail({}, new Transport.SMTP(config))
  const result = await mail
    .send('<p>Hello</p>', message => {
      message
        .from('[email protected]')
        .to('[email protected]')
        .subject('Testing')
    })
} catch(err) {
  // handle the error
}

SMTP Transport

The SMTP transport requires a configuration containing the server connection and authentication parameters. Most email services provide STMP options, so it should be a common transport for most use cases. A basic configuration is provided below, but you can read the nodemailer docs for more advanced options like pooled connections, certificates, etc.

const config = {
  host: 'smtp.thehost.com',
  port: 465,
  secure: false,
  auth: {
    user: 'user',
    pass: 'pass'
  }
}

const mail = new Mail({}, new Transport.SMTP(config))

SES Transport

The SES transport connects to the SES API, a very reliable and affordable mail service. Please refer to the AWS SDK docs for a list of configuration options, especially those in the section "Constructor Details".

const config = {{
  accessKeyId: 'ACCESS_KEY',
  secretAccessKey: 'SECRET_KEY',
  region: 'us-east-1'
}

const mail = new Mail({}, new Transport.SES(config))