ms-mailer
v10.7.0
Published
microservice mailer, incorporates nodemailer functionality with a number of useful plugins over smtp pool transport and amqp messageing layer
Downloads
94
Maintainers
Readme
Mailer Microservice
Sets up a rabbitmq consumer with QoS, and distributes incoming messages based on passed options
Installation
npm i ms-mailer -S
Compatible with node >= 7.6.x
Usage
const Promise = require('bluebird');
const Mailer = require('ms-mailer');
const AMQP = require('@microfleet/transport-amqp');
const mailer = new Mailer({
debug: Boolean,
predefinedLimits: {
maxConnections: Number,
maxMessages: Number,
},
amqp: {
// @microfleet/transport-amqp options
},
htmlToText: {
// https://www.npmjs.com/package/html-to-text
},
accounts: {
test: {
// nodemailer smtp transport configuration
service: 'yahoo',
auth: {
user: '[email protected]',
pass: '123'
}
}
}
});
// returns promise, which resolves when listeners are established
const mailerReady = mailer.connect();
Promise.props({ mailer: mailerReady, amqp: AMQP.connect() })
.then(function sendMessage(props) {
const { amqp } = props;
return amqp.publishAndWait('mailer.predefined', {
account: 'test',
email: {
// nodemailer mail options
// make sure not to pass streams or paths, as they can't be transferred through the wire
// as the processing will be held on the other machine
// in case you want to use some other services like S3, then an expansion can be coded for this module
}
});
})
.then(function sendMessageReponse(response) {
// nodemailer smtp transport response
});
Configuration options
debug
- boolean, whether to print log messages or notprefix
- which route prefix to bind to, defaults tomailer
postfixAdhoc
- which suffix to use for adhoc messagingpostfixPredefined
- which suffix to use for predefined accounts messagingpredefinedLimits
- which opts to pass to smtp transport constructor for predefined accounts, consult nodemailer-smtp-transportamqp
- options that are passed toms-amqp-transport
htmlToText
- html to text conversion options for nodemaileraccounts
- predefined accounts that are initialized at service startup, format is the same as in the nodemailer smtp transport
Messaging format
- Adhoc messaging
mailer.adhoc
:
{
"account": String,
"email": {
// nodemailer email payload
}
}
- Predefined messaging
mailer.predefined
:
{
"account": {
// nodemailer smtp transport format
},
"email": {
// nodemailer email payload
}
}
Roadmap
- test dkim signing
- test different types of messages being sent
- test more error cases
- add QoS handling on demand