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

nodemailer-strategies

v0.0.1

Published

Use multiple email providers, or fall back to disk backups, when using nodemailer. NS avoids providers with high latency intelligently and can also redirect all email to console or disk when testing and debugging.

Downloads

3

Readme

Nodemailer Strategies

Nodemailer Strategies will let you customize your own email strategies, to give you better control if one email providers goes down, or you run your code in test.

With the in-built strategy blocks you can build a strategy that will switch between Gmail and SendGrid, and if both go down, it will fall back to disk. and print the emails to console or you can build a completely different one with suits you better.

When you are testing your application, just replace your production stragy with a Console strategy or a fallback strategy, and you wont have to touch the rest of your email code.

Usage

var nodemailer = require("nodemailer");
var ns = require("nodemailer-strategies");

var googleTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "[email protected]",
        pass: "userpass"
    }
});
var sendGridTransport = nodemailer.createTransport("SMTP",{
    service: "SendGrid",
    auth: {
        user: "apiUser",
        pass: "apiKey"
    }
});

var emailStrategy = new ns([
		{name: "lower-latency", options:[
			{name: "nodemailer", options: googleTransport},
			{name: "nodemailer", options: sendGridTransport}
		]},
		{name: "fallback", options:{ path: "./queuedEmails/"}}
]) 

var mailOptions = {
    from: "Fred Foo ✔ <[email protected]>", // sender address
    to: "[email protected], [email protected]", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world ✔", // plaintext body
    html: "<b>Hello world ✔</b>" // html body
}

emailStrategy.sendMail(mailOptions, function(err, success){
	console.log("Executed the strategy with success? %s", success)
})

Strategy blocks

Fallback to disk

{name:"delay", options:{path: "path to storage directory"}}

Lower Latency

Will use x number of other stragies (usually nodemailer strategies) and use statistics to select the best performing one, and switch favorites if performance degrades.

{name:"lower-latency", options:{providers:[ strategy blocks... ]}}

Console

This strategy will always "fail" and thus proceede to the next strategy in the line.

{name:"console"}

Delay

{name:"delay", options:{time: 1000}}

Nodemailer

{name: "nodemailer", options: nodemailerTransport}

Background

This library was built to ensure that long running node processes can automatically send emails even though one or several of the email providers become offline. Nodemailer Strategies will try email providers in the order the user has determined. It can also use a latency aware wrapper around several email providers to ensure that the most responsive provider is used, and that unstable providers are quickly ignored.

This design was chosen after SendGrid was victim of a DDoS attack and it became apparent that many webapplications have resilient architecture when it comes to application servers, databases and networking equipment, but not e-mail providers.

Contributing

All contributions are welcome. To get your provider accepted, you need to supply tests and notify the maintainers of any needed credentials to test your provider.