1.2.4 • Published 6 years ago

egg-nodemailer-extra v1.2.4

Weekly downloads
27
License
MIT
Repository
github
Last release
6 years ago

egg-nodemailer

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-nodemailer --save

Usage

// {app_root}/config/plugin.js
exports.nodemailer = {
  enable: true,
  package: 'egg-nodemailer-extra',
};

Configuration

// {app_root}/config/config.default.js
exports.nodemailer = {
};

see config/config.default.js for more detail.

Example

// app/config/config.default.js
module.exports = appInfo => {
  const config = exports = {};

  config.nodemailer = {
    host: 'smtp.exmail.qq.com', // your email smtp server
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
      user: 'example@qq.com', // generated ethereal user
      pass: 'password', // generated ethereal password
    },
  };
  return config;
};



// app.js
module.exports = app => {
  app.transporter = app.nodemailer.create(app.config.nodemailer, app);
};


// controller/post.js
const Controller = require('egg').Controller;
class PostController extends Controller {
  async create() {
    const { app } = this;
    let mailOptions = {
      from: 'example@qq.com', // sender address
      to: 'youremail@qq.com', // list of receivers
      subject: 'Hello ✔', // Subject line
      text: 'Hello world?', // plain text body
      html: '<b>Hello world?</b>' // html body
    };
    
   app.transporter.sendMail(mailOptions, (error, info) => {
      if (error) {
        return console.log(error);
      }
      console.log('Message sent: %s', info);
      // Preview only available when sending through an Ethereal account
      console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));

      ctx.body = info;
      ctx.status = 200;
    });
    
   
  }
}
module.exports = PostController;

Questions & Suggestions

Please open an issue here.

License

MIT

1.2.4

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago