egg-mailgun

1.0.2 • Public • Published

egg-mailgun

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

Mailgun Plugin for egg.

This plugin based on mailgun-js, if you want to know specific usage, you should refer to the document of mailgun-js.

Install

$ npm i egg-mailgun --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.mailgun = {
  client: {
    // api key
    apiKey: 'your api key',
    // domain
    domain: 'your domain name',
  },
  // load into app, default is open
  app: true,
  // load into agent, default is close
  agent: false,
};

see config/config.default.js for more detail.

Example

Sending Messages

use mailgun api at controller:

// {app_root}/app/controller/email.js
const Controller = require('egg').Controller;
 
class EmailController extends Controller {
  async send() {
    const data = {
      from: 'Excited User <me@samples.mailgun.org>',
      to: 'bar@example.com, YOU@YOUR_DOMAIN_NAME',
      subject: 'Hello',
      text: 'Testing some Mailgun awesomness!'
    };
 
    this.ctx.body = await this.app.mailgun.messages().send(data);
  }
}
 
module.exports = EmailController;

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-mailgun

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

8.41 kB

Total Files

7

Last publish

Collaborators

  • sundaymorning