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

nodemailing

v1.1.2

Published

Send emails in NodeJs with no configuration required

Downloads

33

Readme

NodeMailing - Easily Send Emails in NodeJS

Yes! No Configuration Needed

Nodemailing is a lightweight emailing system that takes advantage of SMTP to allow users to easily send emails with no configuration at all.

In fact, all you need do is to require the Nodemailing module and call the send funtion. Pass your SMTP Host, username, password, recipient, subject, body, and voila! Your messages gets sent immediately.

To get started run

npm install nodemailing

or go the shorter route

npm i nodemailing

Now, in your NodeJS project, require nodemailing.

const nodemailing = require('nodemailing');

Now, easily send your email

nodemailing.send({
   Host: //your smtp host,
   Username: //your email,
   Password: //your email password or app password,
   To: //recipient email,
   From: //your email,
   Subject: //email subject,
   Body: //email body,
}).then((message) =>
//anything goes here....
    console.log("Email has been sent")
);

Tell your recipient to check thier mail, your email just got delivered...!

You Can Also Send Dynamic HTML Email Templates

Create your HTML email template and add the variables you want to modify in {{variable-name}}. Below is a sample.

<div>
  <h1>Welcome to Nodemailing 101</h1>

  <p>Dear {{username}},</p>
  <p>
    We are so excited to have you here. Nodemailing is a great package and we
    can be sure you will love it!
  </p>

  <p>
    Got any questions as regards this package? You can reach us on GitHub via
    this username: <strong>{{githubID}}</strong>
  </p>
</div>

Now that you have your HTML template ready. Call Nodemailing render function and pass in the path to your HTML template and the data object containing the values for the variables.

// import nodemialing
const nodemailing = require('nodemailing');
// import the path function
const path = require('path');

// define the path to the HTML template
const filePath = path.join(__dirname, 'relative/path/to/html/file');

// compute the data for the variables
data = {
  username: 'Perfection',
  githubID: 'Samperfect',
};

// this method uses the await syntax to avoid callback hell
async function createTemp() {
  // call nodemailing to render the email
  const emailToSend = await nodemailing.render(filePath, data);

  //   now call nodemailing to send your mail
  nodemailing.send({
   Host: , //your smtp host
   Username: , //your email
   Password: , //your email password or app password
   To: , //recipient email
   From:,  //your email
   Subject: "Welcome Message",
   Body: emailToSend,
}).then((message) =>
//anything goes here.... it returns **OK** by default
    console.log(message, "Email has been sent")
).catch(error=>{
// who knows, an error might just occur
    console.log(error)
});
}

// don't forget to call the function
createTemp()

And if you prefer to use .then() and .catch(), then you might as well fall into the callback hell below 😎

// import nodemialing
const nodemailing = require('nodemailing');
// import the path function
const path = require('path');

// define the path to the HTML template
const filePath = path.join(__dirname, 'relative/path/to/html/file');

// compute the data for the variables
data = {
  username: 'Perfection',
  githubID: 'Samperfect',
};

// call nodemailing to render the email
nodemailing.render(filePath, data).then(emailToSend =>{
  // now call nodemailing to send your mail
  nodemailing.send({
   Host: , //your smtp host
   Username: , //your email
   Password: , //your email password or app password
   To: , //recipient email
   From:,  //your email
   Subject: "Welcome Message",
   Body: emailToSend,
}).then((message) =>
//anything goes here.... it returns **OK** by default
    console.log(message, "Email has been sent")
).catch(error=>{
// who knows, an error might just occur
    console.log(error)
});
}).cath(error=>{
    console.log(error)
});

Tell your recipient to check thier mail, your email just got delivered...!