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

nodejs-email-service

v0.0.2

Published

This service helps to send emails using nodejs. Send multiple different types of emails with their corressponding templates all with one functions.

Downloads

10

Readme

NODEJS EMAIL SERVICE

Hey there, here are the steps required to use this package.

Getting Started

First off, let's start by installing the npm package by running

npm i nodejs-email-service

After installing the package, let's move on to initializing the package in our server root directory or desired file of your choice.

To initialize it, we write the following;

const nodejs_email_service = require('nodejs-email-service');

const email_service = new nodejs_email_service(config, properties)

Arguments Explained

CONFIG: The config object consists the parameters required to setup your mailing service. These parameters include;

service: This is the service you want to use. This could be gmail, mailgun e.t.c.

host: The host required by your mail service provider. Should be in your service provider instructions. E.g smtp.mailgun.org for mailgun e.t.c

user <required>: The user provided by your mail service provider.

pass <required>: The password provided by your mail service provider.

port: The host required by your mail service provider. Should be in your service provider instructions. E.g 587 for mailgun e.t.c

Note: Your user and pass should be private and therefore be set as an environment variable

PROPERTIES: The properties object consisits the parameters required to configure your custom templating system for the package to use. These parameters include;

extensionName: This is the extension name of your template file. E.g .handlebars or .hbs

partialsDir: This is the relative path to your partials directory.

layoutsDir: This is the relative path to your layouts directory.

viewPath: This is the relative path to your templates directory.

When used with the parameters, we have something like this:

const nodejs_email_service = require('nodejs-email-service');

const email_service = new nodejs_email_service(
    {
        host: 'smtp.mailgun.org',
        service: 'Mailgun',
        user: process.env.MAILGUN_USERNAME,
        pass: process.env.MAILGUN_PASSWORD
    },
    {
        partialsDir: './mock-templates-1/partials',
        layoutsDir: './mock-templates-1/layouts',
        viewPath: './mock-templates-1/templates',
        extensionName: '.handlebars'
    }
)

Note: To use the default template to check if it works, do not pass in the properties argument as it is optional.

SENDING EMAILS

To start sending emails, all you have to do is call our sendEmail function with the necessary parameters.

 email_service.sendEmail(parameters)

These parameters include;

to <required> : This is the recipient of the email. Pass in an array for multiple recipients.

sender: This is the sender of the email. This is a string and can be written how ever you want.

subject: This is the subject of the email.

template: This is the template which you want this service to use and is only required if you passed in layoutsDir and viewPath during initialization.

context: This is used to add dynamic data into your mail template. For Instance, if we want to greet our mail recipient or call them by their names, we could easily pass in their names to the sendEmail function. Let's see the context argument as a way to pass any meta data we want on to our recipient.

When use with it's parameters, we have;

email_service.sendMail({
        to: "[email protected]",
        sender: '[email protected]',
        subject: 'First Time User',
        template:  'dummy-2',
        context: {
            name: 'Name of recipient',
            gender: 'Male'
        }
     })

And that's it, that's all you need to start sending emails from your server. Thanks for using our package.

Notice something wrong? Reach out via email, twitter, medium