Sets up a rabbitmq consumer with QoS, and distributes incoming messages based on passed options
npm i ms-mailer -S
Compatible with node >= 7.6.x
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
});
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
- Adhoc messaging
mailer.adhoc
:
{
"account": String,
"email": {
// nodemailer email payload
}
}
- Predefined messaging
mailer.predefined
:
{
"account": {
// nodemailer smtp transport format
},
"email": {
// nodemailer email payload
}
}
- test dkim signing
- test different types of messages being sent
- test more error cases
- add QoS handling on demand