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.
$ npm i egg-mailgun --save
// {app_root}/config/plugin.js
exports.mailgun = {
enable: true,
package: 'egg-mailgun',
};
// {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.
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;
Please open an issue here.