egg-mailgun
v1.0.2
Published
mailgun plugin for eggjs
Downloads
5
Maintainers
Readme
egg-mailgun
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 <[email protected]>',
to: '[email protected], 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.