warp.email-processor

0.1.4 • Public • Published

warp.email-processor

Overview

warp.email-processor allows to queue and bulk-send emails. It supports HTML and text templates and consists of two methods: 1. queue - adds email metadata to a mongoDB collection; 2. process - sends all the unprocessed emails using the metadata from mongoDB;

Changes

0.0.4 - SendGrid support, settings object format changes

Usage

Create instance of email-processor

EmailProcessor = require('warp.email-processor');
email = new EmailProcessor({
	relativeTemplatesPath: 'path/to/your/templates/',
	collection: db.collection('emails'),
	service: 'Gmail',
	auth: {
		user: 'example@gmail.com',
		pass: 'secret'
	}
	}
});

*warp.email-processor uses nodemailer module, check the module description for an explanation of service settings.

Queue some emails

email.queue({recipient: 'recipient@example.com', sender: 'sender@example.com', subject: 'hello' , optionalKey1: 'foo', optionalKey2: 'bar'}, 'marketingTemplate', function(err){
    if (err) {
       console.log(err);
    }
    else {
    	 console.log('email is ready to be sent');
    }
});

Prepare your template

Put the following html into path/to/your/templates/marketingTemplate/index.html

<table >
	<tr>
		<td>
			Buy what we sell! It is really good! Especially !!optionalKey1!! and !!optionalKey2!!.
		</td>
	</tr>
</table>

This will result in:

<table >
	<tr>
		<td>
			Buy what we sell! It is really good! Especially foo and bar.
		</td>
	</tr>
</table>

Process (send your emails)

email.process(function(err) {
	if (err){
		console.log(err);
	}
	else {
		console.log('all emails are sent!');
	}
});

Using Sendgrid

The only difference is the options object passed:

EmailProcessor = require('warp.email-processor');
email = new EmailProcessor({
	relativeTemplatesPath: 'path/to/your/templates/',
	collection: db.collection('emails'),
	service: 'Sendgrid', //!!
	auth: {
		user: 'username',
		pass: 'secret'
	},
	// optionally you can pass request parameter which will be passed to sendgrid npm module, which in turn passes in to the request npm module
	// for example to use proxy:
	request: {
    	proxy: "http://localproxy:3128" 
    }
});

Readme

Keywords

Package Sidebar

Install

npm i warp.email-processor

Weekly Downloads

2

Version

0.1.4

License

ISC

Last publish

Collaborators

  • antonmiselaytes