egg-multipart-mailer
v1.0.6
Published
可用于多个发送人配置的邮件插件,可用于saas系统,根据实时配置实例化发送邮件实例
Downloads
10
Maintainers
Readme
egg-multipart-mailer
nodemailer plugin for Egg.js.
可用于多个email发送实例插件; 可用于saas系统; 根据实时配置实例化发送邮件实例。
Install
$ npm i egg-multipart-mailer --save
Usage
// {app_root}/config/plugin.js
exports.multipartMailer = {
enable: true,
package: 'egg-multipart-mailer',
};
Configuration
// {app_root}/config/config.default.js
不用配置,调用时才传入
exports.multipartMailer = {
};
see nodemailer for more detail.
Example
// app/controller/home.js
class HomeController extends Controller {
async index() {
const { ctx, app } = this;
const config ={
// host: "smtp.ethereal.email",
service: "qq",
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass // generated ethereal password 如何获取这些密码。参考https://blog.csdn.net/qq_40571631/article/details/89206851
}
};
const mailer = this.app.initMultipartMailer(config);
// 注意下面的from的值要跟上面的cofig.auth.user的一样
// sync
await mailer.send({
from: testAccount.user, // sender address
// // 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
mailer.send({
from: testAccount.user,
// 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, multipart mailer';
}
}