egg-mailer

    1.5.0 • Public • Published

    egg-mailer

    nodemailer plugin for Egg.js.

    NPM version build status Test coverage David deps Known Vulnerabilities npm download

    README | 中文文档

    Install

    $ npm i egg-mailer --save

    Usage

    // {app_root}/config/plugin.js
    exports.mailer = {
      enable: true,
      package: 'egg-mailer',
    };

    Configuration

    // {app_root}/config/config.default.js
    exports.mailer = {
      host: "smtp.ethereal.email",
      port: 587,
      secure: false, // true for 465, false for other ports
      auth: {
        user: testAccount.user, // generated ethereal user
        pass: testAccount.pass  // generated ethereal password
      }
    };

    see nodemailer for more detail.

    Example

    // app/controller/home.js
    class HomeController extends Controller {
      async index() {
        const { ctx, app } = this;
        // sync
        await app.mailer.send({
          from: '"Fred Foo 👻" <foo@example.com>', // sender address, [options] default to user
          // // Array => ['bar@example.com', 'baz@example.com']
          to: "bar@example.com, baz@example.com", // list of receivers
          subject: "Hello ✔", // Subject line
          text: "Hello world?", // plain text body
          html: "<b>Hello world?</b>" // html body
        });
        // async
        app.mailer.send({
          from: '"Fred Foo 👻" <foo@example.com>',
          // Array => ['bar@example.com', 'baz@example.com']
          to: "bar@example.com, baz@example.com",
          subject: "Hello ✔",
          text: "Hello world?",
          html: "<b>Hello world?</b>"
        }, function (err, info) {
          if (err) {
            throw err;
          }
          console.log(info);
        });
        ctx.body = 'hi, mailer';
      }
    }

    Questions & Suggestions

    Please open an issue here.

    License

    MIT

    Install

    npm i egg-mailer

    DownloadsWeekly Downloads

    138

    Version

    1.5.0

    License

    MIT

    Unpacked Size

    9.25 kB

    Total Files

    6

    Last publish

    Collaborators

    • xjh22222228