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

bocartero

v1.1.0

Published

A ready-made nodeMailer wrapper for my apps

Downloads

13

Readme

Foo

BoCartero

BoCartero is a very very simple Node.js + NodeMailer wrapper class created to be used in node backends.

The intention behind it is to simply NodeMailer use and keep its impact on code readability to a minimum by relying on process.env variables and configuring NodeMailer transport directly from i.e. the projects's .env file.

Installation

Use Node Package Manager npm to install BoCartero.

cd <path to folder containing your package.json file>

npm install bocartero

Usage

const { BoCartero } = require("bocartero");

/*** IMPORTANT!
 *
 * To keep code minimal, BoCartero relies on the following env variables.
 * These need to be defined (i.e. in your .env file, or in other ways).
 *
 * If any of the required env vars is not defined (i.e. not found in the process.env object)
 * the constructor and/or the sendEmail function will throw an exception.
 *
 * SMTP_SERVICE='hotmail' # If not using outlook.com, set this to anything else - NOTE: it HAS to be present.
 * SMTP_HOST='<your SMTP host>' ### Not needed with 'hotmail' option.
 * SMTP_PORT=<your SMTP host's Port> ### Not needed with 'hotmail' option.
 * SMTP_USER="<your username to sign in to SMTP server>"
 * SMTP_PASSWORD="<password for that username>"
 *
 * Also, sendEmail function needs these to be defined:
 *
 * SMTP_EMAIL_FROM='<email account that appears to have sent these emails>'
 * SMTP_DEFAULT_EMAIL_TO='<default address to send all emails to (if not overriden in sendEmail method)>'
 *
 ****/

// Get the env vars:
if (!process.env.NODE_ENV) require("dotenv").config();

const mailman = new BoCartero();

// You can rely on default emailTo & text:
mailman.sendEmail("test email A", "<p>Hello world</p>");

// Or you can override the default emailTo:
mailman.sendEmail("test email B", "<p>Hello world!</p>", "[email protected]");

// The 4th parameter is the text content of the email.
// If not provided it will default to "NOTE: this email was sent in HTML format only."
mailman.sendEmail(
  "test email C",
  "<p>Hello world!</p>",
  "[email protected]",
  "Hello world!" // (this is what you'll see if your email client does not render the HTML content)
);

Why the rather anachronistic emphasis on hotmail?

I did a few websites for non-profit organizations and needed a free SMTP server. I found out Gmail is (more secure but) extremely annoying. Even if you do things by the book, it's heuristic analysis might reject your request to send an email at potentially unpredictable times (at least in my tests). So I tried different options (such as Mailgun and others) but in the end the least complicated was good old 'hotmail' (Outlook.com free accounts).

So as far as defaults go, I default to this. History will judge me ¯\(ツ)

But of course you can configure your own SMTP server!

Just set env variable SMTP_SERVICE to something other than 'hotmail'. It doesn't matter what (the actual value won't be used unless it's 'hotmail') but you do have to define it. It has to be present in your process.env object (to make sure you didn't omit it by mistake - this made sense at some point and is still the way it goes for now!)

In this case you also need to define the env vars SMTP_HOST and SMTP_PORT.

License

MIT