egg-mailer
v1.5.0
Published
mailer plugin for egg
Downloads
412
Maintainers
Readme
egg-mailer
nodemailer plugin for Egg.js.
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 👻" <[email protected]>', // sender address, [options] default to user
// // Array => ['[email protected]', '[email protected]']
to: "[email protected], [email protected]", // 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 👻" <[email protected]>',
// Array => ['[email protected]', '[email protected]']
to: "[email protected], [email protected]",
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.