https://github.com/makeomatic/ms-mailer-client
Encapsulates routes and provides convenience methods to send emails
https://github.com/makeomatic/ms-mailer-client
Last synced: 5 months ago
JSON representation
Encapsulates routes and provides convenience methods to send emails
- Host: GitHub
- URL: https://github.com/makeomatic/ms-mailer-client
- Owner: makeomatic
- License: mit
- Created: 2015-11-10T19:42:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-20T17:57:37.000Z (about 2 years ago)
- Last Synced: 2025-02-05T14:08:02.868Z (about 1 year ago)
- Language: JavaScript
- Size: 542 KB
- Stars: 0
- Watchers: 7
- Forks: 1
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mailer microservice client
Encapsulates raw AMQP methods into a convenience wrapper.
## Installation
`npm i ms-mailer-client -S`
## Usage
```js
const Mailer = require('ms-mailer-client');
const mailer = new Mailer(amqpTransport, {
prefix: 'mailer',
routes: {
adhoc: 'adhoc',
predefined: 'predefined'
}
});
// use predefined email
const promisePredefined = mailer.send('support@makeomatic.ru', {
// email body with nodemailer
});
// use adhoc account
const promiseAdhoc = mailer.send({
// nodemailer smtp data
service: 'gmail',
auth: {
}
}, {
// nodemailer email body
});
```
### `send` method
```js
const Mailer = require('ms-mailer-client');
const mailer = new Mailer(transport, { /* config */ });
const promise = mailer.send('support@makeomatic.ru', {
// nodemailer email body
from: 'support@makeomatic.ru',
to: 'test@example.com',
subject: 'subj',
text: 'some text',
html: '
html version of some text
',
});
```
### `sendTemplate` method
```js
const Mailer = require('ms-mailer-client');
const mailer = new Mailer(transport, { /* config */ });
// can be used with adhoc account setup aswell
const promise = mailer.sendTemplate(
'support@makeomatic.ru',
'reset', // template name
{
nodemailer: {
from: 'support@makeomatic.ru',
to: 'test@example.com',
subject: 'subj',
},
ctx: {
// template rendering context
link: 'activation_link',
name: 'John Doe',
},
}
);
```
Resulted promise can be fulfilled with rejection when
the requested template name does not exist.