koa-mailer

0.1.0 • Public • Published

koa-mailer

NPM Licence Downloads

Koa middleware to send emails.

Usage

const koa = require('koa');
const mailer = require('koa-mailer');
 
const app = koa();
 
app.use(mailer({
  email: {
    host: 'smtp.xxx.com',
    port: 25,
    secure: false,
    auth: {
      user: 'example@xxx.com',
      pass: 'password',
    },
  },
  prefix: '/mailer',
  validate: function (ctx) {
    const blacklist = [
      '127.0.0.1',
      '8.8.8.8',
    ];
    return blacklist.indexOf(ctx.ip) < 0;
  },
  handlers: {
    '/notice': function (body) {
      return {
        to: body.to,
        subject: 'Notice',
        html: body.html,
        text: body.text,
      };
    },
  },
}));
 
app.listen(8080);

Documents

const mailer = require('koa-mailer');
 
app.use(mailer(options));
  • options.email

    required Object

    The auth info to be passed to nodemailer.

  • options.prefix

    optional String

    The path prefix for routes. Default as ''.

  • options.validate

    optional Function (ctx)

    A function to decide whether the request should be rejected. The only parameter is the Koa Context.

  • options.handlers

    optional Object

    A map of routes to handlers. Each handler is a function with the post data as parameter, which should return the email data to be sent.

Readme

Keywords

Package Sidebar

Install

npm i koa-mailer

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • gera2ld