egg-mailer

mailer plugin for egg

Usage no npm install needed!

<script type="module">
  import eggMailer from 'https://cdn.skypack.dev/egg-mailer';
</script>

README

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