mailer-q
v2.0.2
Published
A redis-backed mailer queue system
Downloads
7
Readme
MailerQ
MailerQ is a Redis-backed mailer queue system.
Installation
npm install mailer-q --save
Usage
- It is easiest to have MailerQ's configuration in another module:
config/mailers.js
const MailerQ = require("mailer-q")();
const options = {
//Options here
};
module.exports = MailerQ.config(options);
Available Options for MailerQ Configuration
- nodemailer: Configuration object for Nodemailer. An example is shown below but all options can be found in the Nodemailer documentation here: https://nodemailer.com/smtp/.
- defaultFrom (Optional): Set the default sender
- defaultTo (Optional): Set the default recipient (not common)
- renderer (Optional): Method to render email templates
- sendAttempts (Optional): Number of times MailerQ will attempt to send your mail. Defaults to 3.
- redis (Optional): Configuration options to configure Redis. These configuration options come from ioredis and you can find all options in their documentation here: https://github.com/luin/ioredis/blob/master/API.md.
Example:
const config = {
nodemailer: {
host: "smtp.example.com",
port: 587,
auth: {
user: "your username",
pass: "your pass"
}
},
defaultFrom: "Test Tester [email protected]",
defaultTo: "[email protected]",
sendAttempts: 5
};
Optional Renderers
- EJS Renderer: Use the EJS templating syntax.
- Handlebars Renderer: Use the Handlebars templating syntax.
- Pug Renderer: Use the Pug templating syntax.
Sending Mail
- The module has two methods -
deliverNow
anddeliverLater
. deliverNow
will attempt to send the email message immediately, vsdeliverLater
will use Redis to queue this action up for a later time.deliverNow
anddeliverLater
must be chained withcontents
, which sets up the content to be sent.
Example:
const MailerQ = require("./config/mailers");
MailerQ.contents({
from: "Test Sender [email protected]",
to: "[email protected]",
subject: "Test message",
htmlBody: "<h1>HTML message here!</h1>"
})
.deliverNow()
.then(() => {
console.log("Message sent!");
})
.catch((err) => {
console.log(err);
});
Available Options for .contents()
- subject: Subject of message
- from (Optional): Email address of sender. Optional only if not using defaultFrom in the initial configuration.
- to (Optional): Email address of recipient. Optional only if not using defaultTo in the initial configuration.
- templateFileName (Optional): Name of file used as template (only use this if you're using a renderer plugin)
- htmlBody (Optional): HTML to send in email message
- locals (Optional): Object of local variables to be used in renderer (only use this if you're using a renderer plugin)
- attachments (Optional): Array of attachment objects as specified by Nodemailer: https://nodemailer.com/message/attachments/.