Skip to content

Encapsulates routes and provides convenience methods to send emails

License

Notifications You must be signed in to change notification settings

makeomatic/ms-mailer-client

Repository files navigation

Mailer microservice client

Encapsulates raw AMQP methods into a convenience wrapper.

Installation

npm i ms-mailer-client -S

Usage

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('[email protected]', {
  // email body with nodemailer
});

// use adhoc account
const promiseAdhoc = mailer.send({
  // nodemailer smtp data
  service: 'gmail',
  auth: {

  }
}, {
  // nodemailer email body
});

send method

const Mailer = require('ms-mailer-client');
const mailer = new Mailer(transport, { /* config */ });

const promise = mailer.send('[email protected]', {
  // nodemailer email body
  from: '[email protected]',
  to: '[email protected]',
  subject: 'subj',
  text: 'some text',
  html: '<p>html version of some text</p>',
});

sendTemplate method

const Mailer = require('ms-mailer-client');
const mailer = new Mailer(transport, { /* config */ });

// can be used with adhoc account setup aswell
const promise = mailer.sendTemplate(
  '[email protected]', 
  'reset', // template name
  {
    nodemailer: {
      from: '[email protected]',
      to: '[email protected]',
      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.

About

Encapsulates routes and provides convenience methods to send emails

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •