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

email-alert

v1.0.0

Published

A configurables email alert and notifier objects for administrators

Downloads

3

Readme

EmailAlert

This is a NodeJS module for Email Alerts and Notifications.

Installation

From a command prompt with npm installed, type in npm install email-alert, or npm install --save email-alert if you want to install this package and add it to your package.json file.

Usage

This module exposes constructors for two different objects: EmailAlerter and EmailNotifier, both of which wrap the email NodeJS module.

The EmailAlerter object exists essentially just for consistency. It takes a configuration object as a parameter. If no configuration parameters are provided, sensible defaults are chosen. Emails are sent immediately upon invoking EmailAlerter's alert() method. The EmailAlerter object is intended to be used for important notifications requiring immediate action.

The EmailNotifier object is similar to the EmailAlerter object, but instead of sending the email immediately, it queues messages in a buffer, and sends an email every so often (the interval is configurable) containing all of the updates. Messages are added to the queue with EmailNotifier's notify() method. The EmailNotifier object is intended to be used for less important notifications.

Configuration

The configuration object passed into the constructors of both the EmailAlerter and the EmailNotifier take the following options, most of which speak for themselves:

{
    // The source address.
    // Defaults to (your username)@(your hostname).
    from: "[email protected]", 

    // The email address that should receive replies.
    // Defaults to null.
    replyTo: "[email protected]", 

    // The list of email addresses that should receive the alerts.
    // Defaults to [ (your username)@(your hostname) ]
    to: [ "[email protected]", "[email protected]" ], 

    // The list of email addresses that should be CC'd the alerts.
    // Defaults to []
    cc: [ "[email protected]", "[email protected]" ],

    // The list of email addresses that should be BCC'd the alerts.
    // Defaults to []
    bcc: [ "[email protected]", "[email protected]" ],

    // The subject of the email that gets sent.
    // Defaults to "Notifications|Alert from (your hostname)"
    subject: "You have notifications!",

    // Whether to use HTML in the message.
    // Defaults to false
    html: true,

    // The Header that appears before the message of the alert or notifications
    // Defaults vary sensibly with HTML option and alert or notification.
    header: "<h1>You've got alerts!</h1>",

    // The Footer that appears before the message of the alert or notifications
    // Defaults vary sensibly with HTML option and alert or notification.
    footer: "<i>Copyright 2001 (C) A Odyssey</i>",

    // The length of time (in seconds) between which notification emails are sent
    // Note that no notification email is sent if there are no notifications.
    // Also note that this setting only applies to EmailNotifier.
    // Defaults to one hour (3600000 milliseconds)
    notificationInterval: 30,

    // The file path where sendmail can be found
    // Defaults to just "sendmail" and lets the shell do the digging.
    sendmailPath: "/usr/bin/sendmail"
}

Examples

The simplest setup you can do:

var ea = require("email-alert");

var emailAlerter = new ea.EmailAlerter({
    from: "[email protected]",
    to: [ "[email protected]" ]
});

var emailNotifier = new ea.EmailNotifier({
    from: "[email protected]",
    to: [ "[email protected]" ]
});

// Immediately sends an email to the configured destinations.
emailAlerter.alert("Memory usage is high!");

// Queues the following messages, then eventually sends them all in one email.
emailNotifier.notify("A user joined your channel.");
emailNotifier.notify("Backup taken at 4:04.");
emailNotifier.notify("Coffee is done brewing.");

Todo

  • [ ] Implement getters for all settings
  • [ ] Maybe implement setters for all settings
  • [ ] Implement assert.throws() tests
  • [ ] Implement assert.doesNotThrow() tests

Bugs

Currently, you may not use email addresses whose domain part contains only a single component, such as user@localhost. I am working on it.

Contact Me

If you would like to suggest fixes or improvements on this library, please just comment on this on GitHub. If you would like to contact me for other reasons, please email me at [email protected]. :boar: