https://github.com/makeomatic/ms-mailer
Simple microservice for sending emails, relies on nodemailer and ms-amqp-transport
https://github.com/makeomatic/ms-mailer
Last synced: 10 months ago
JSON representation
Simple microservice for sending emails, relies on nodemailer and ms-amqp-transport
- Host: GitHub
- URL: https://github.com/makeomatic/ms-mailer
- Owner: makeomatic
- License: mit
- Created: 2015-11-03T16:32:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-20T17:35:54.000Z (about 2 years ago)
- Last Synced: 2024-09-21T13:22:30.860Z (over 1 year ago)
- Language: JavaScript
- Size: 1.5 MB
- Stars: 6
- Watchers: 7
- Forks: 7
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Mailer Microservice
Sets up a rabbitmq consumer with QoS, and distributes incoming messages based on passed options
[](https://badge.fury.io/js/ms-mailer)
[](https://semaphoreci.com/makeomatic/ms-mailer)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
[](https://codecov.io/github/makeomatic/ms-mailer?branch=master)
## Installation
`npm i ms-mailer -S`
Compatible with node >= 7.6.x
## Usage
```js
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: 'test@yahoo.com',
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
1. `debug` - boolean, whether to print log messages or not
2. `prefix` - which route prefix to bind to, defaults to `mailer`
3. `postfixAdhoc` - which suffix to use for adhoc messaging
4. `postfixPredefined` - which suffix to use for predefined accounts messaging
5. `predefinedLimits` - which opts to pass to smtp transport constructor for predefined accounts, consult nodemailer-smtp-transport
6. `amqp` - options that are passed to `ms-amqp-transport`
7. `htmlToText` - html to text conversion options for nodemailer
8. `accounts` - predefined accounts that are initialized at service startup, format is the same as in the nodemailer smtp transport
## Messaging format
1. Adhoc messaging `mailer.adhoc`:
```js
{
"account": String,
"email": {
// nodemailer email payload
}
}
```
2. Predefined messaging `mailer.predefined`:
```js
{
"account": {
// nodemailer smtp transport format
},
"email": {
// nodemailer email payload
}
}
```
## Roadmap
1. test dkim signing
2. test different types of messages being sent
3. test more error cases
4. add QoS handling on demand