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

krakenjs-mailer

v0.1.3

Published

Nodemailer and dust template integration

Downloads

3

Readme

KrakenJs Mailer

KrakenJs, Nodemailer, and Dust Integration.

Purpose

KrakenJs Mailer allows the developer to utilize nodemailer's emailing system with KrakensJs's integrated dust templating system. This integration allows a simple one method control for sending emails in KrakenJs's framework

Getting Started

  1. Install the KrakenJs Mailer via

    npm install krakenjs-mailer --save
  2. Enter in your SMPT details in config/mail.json

  3. Add the require to the top of your controller (notice the passing of app) under the module.exports call

    module.exports = function (app) {
        var mail = require('krakenjs-mailer')(app);
  4. Create the send call in your controller:

    mail.send({
    	template: 'your-email-message',	
    	message: {
    		to: '[email protected]',
    		data: {name:'Frank Foo'}
    	}
    });
  5. Profit

NOTE We try to install Nodemailer globally, however if the console output mentions it was not installed, please install it via

sudo npm install nodemailer -g

Example: Full Controller

// controllers/mail.js
module.exports = function (app) {
	var mail = require('krakenjs-mailer')(app);

    app.get('/mail', function (req, res) {
    
    	mail.send({
    		template: 'your-email-message',	
    		message: {
    			to: '[email protected]',
    			data: {name:'Frank Foo'}
    		}
    	});
    
    	res.end();
    });
};

File and Directory structure

  • /config/mail.js - Default configuration
  • /public/templates/mail/ - Email templates

Customization

KrakenJs Mailer is more of a "plugin" to KrakenJs. Thus

var mail = require('krakenjs-mailer')(app)

has the app passed in. This allows the most flexible access to KrackenJs without creating middleware, etc.

Config

config/mail.json contains the default configurations for Nodemailer and krakenjs-mailer including the config options for Nodemailer's message and create options. The message default will extend with every custom message option that is sent through the module

Example:

{	
	"create": {
		"service": "Gmail",
		"auth": {
			"user": "[email protected]",
			"pass": "securepassword"
		}
	},
	"message": {
		"from": "Your Comapany <[email protected]>",
		"subject": "Your Company Message"
	}
}

Send

The only public method is send(options). However the options param will allow overrides of nodemailer's message and create options.

Options Param (required)

{
	template: ''        // (required) the name or path of the template (mail/ will be prefixed when no directories are detected)
	message : {         // (required) will extend from message in config/mail.json
		data : {}/[],   // (required) literal or array that is passed to dust template
                        // an array will iterate through the data, apply the template, and send each message individually
		* : {}          // (optional) all other options availiable passed to nodemailer's message options
	}, 
	create : {}         // (optional) will extend from create in config/mail.json and passed to nodemailer's create options
}

Example An Single Message:

mail.send({
	template: 'notify',	
	message: {
		subject: 'Messaging Frank Foo',
		to: '[email protected]',
		data: {name:'Frank Foo'}
	}
});

Example An Array of Messages:

mail.send({
	template: 'notify',
	message: [
		{
			subject: 'Messaging Frank Foo',
			to: '[email protected]',
			data: {name:'Frank Foo'}
		},
		{
			subject: 'Messaging Brad Bar',
			to: '[email protected]',
			data: {name:'Brad Bar'},
		}
	]
});

Questions and Contributing to KrakenJs Mailer

Bugs and new features should be submitted using Github issues.

FAQ

Can I use another templating system other than KrackenJs's Dust?

Technically, yes. However the templating system must NOT cache as multiple messages must be unique.

Can I use another mailer other than Nodemailer?

No. It probably never will be. Thus the name krankenjs-mailer. It is a name merge of KrakenJs and Nodemailer.

Can I use another mail protocol other than SMPT?

No not at this time. But you can contribute to add that option.