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

light-mailer

v1.2.2

Published

You can use this automated version of nodemailer to send emails easily.

Downloads

3

Readme

Light Mailer

You can utilize this automated version of Nodemailer to easily send emails. All you need to do is create a REST API by integrating Light Mailer and then make a request to it using a frontend, including the necessary data you want to send in the email.

Why Light Mailer

  • Easy to use.
  • No any advanced configurations. (Configured everything in nodemailer for you.)
  • Best for small projects.

Installation

You can install this package using npm:

npm install light-mailer

Usage

Quick Tutorial

First import necessary modules into your project:

const lightMailer = require('light-mailer');
const express = require("express");
const fs = require("fs");

Next, create an email template and read its content like this:

const template = fs.readFileSync("./template.html", "utf8");

The email template must include placeholders with the exact names of the keys of the JavaScript object which you receive in the request body. (Please declare the placeholders like this: {{}} ) In this case, the email template will look like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>Name - {{name}}</p>
    <p>Name - {{message}}</p>
</body>
</html>

Then create a REST API using Express.js and add the API endpoint "/send-mail" as follows:

const app = express();
const PORT = 4000 || process.env.PORT;

app.use(express.json());

app.post("/send-mail", (req, res) => {
    // ...
});

app.listen(PORT, (req, res) => {
    console.log("Server is running on port", PORT);
});

After that, you can get the data that you want to send as an email from the request body. Next, create a new instance of lightMailer with the necessary arguments. Then call the sendMail function with the data that you want to send as an email and the email template. Finally, write the response as follows:

app.post("/send-mail", async (req, res) => {
    const data = req.body;

    const mail = new lightMailer(
        "[email protected]",
        "your-gmail-app-password",
        "receiver'[email protected]"
    );

    try {
        await mail.sendMail(data, template, "The Subject...");

        res.status(200).json({
            status: "success",
            data: {
                message: "Email sent successfully!",
            },
        });
    } catch (error) {
        res.status(400).json({
            status: "failed",
            data: {
                message: error.message,
            },
        });
    }
});

Please create an app password for gmail and put it in the arguments.

You can check if the API works using Postman. Just make a POST request to the following link: 127.0.0.1:4000/send-mail and add the JSON object below to the request body.

{
    "name": "Example",
    "message": "Hello World!"
}

Afterward, check the recipient's email address that you provided when creating the lightMailer instance. This is the end of the quick tutorial.

Functions & Parameters

These functions include the lightMailer function, which was created in the quick tutorial. Note that you can use any name for that!

| Function | Parameters | |----------|----------| | lightMailer | Sender's email, Password, Receiver's email | | sendMail | data, template |

Changelog

All notable changes to this project will be documented in this section.

[1.2.2] - 2024-04-23

Changed

  • Minor bug fixes

[1.2.0] - 2024-04-22

Changed

  • Improved error handling

Fixed

  • Authentication issue with gmail passwords

[1.0.8]

  • Initially Released

License

This project is licensed under the MIT License - see the LICENSE.md file for details.