1.0.6 • Published 3 years ago

egg-multipart-mailer v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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 => ['bar@example.com', 'baz@example.com']
      to: "bar@example.com, baz@example.com", // 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 => ['bar@example.com', 'baz@example.com']
      to: "bar@example.com, baz@example.com",
      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';
  }
}

License

MIT

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago