Code Monkey home page Code Monkey logo

egg-sendmail's Introduction

egg-sendmail

Nodemailer plugin for Egg.js.

Install

npm i @axolo/egg-sendmail --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.sendmail = {
  client: {
    from: '"no-reply" <no-reply@localhost>',  // mail from
    smtp: { // smtp server
      host: 'smtp.local.host', // smtp host
      port: 465, // smtp port
      secure: true, // true for 465, false for other ports
      auth: {
        user: '[email protected]', // mail
        pass: 'password', // password
      },
    },
  },
};

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

Example

// /app/controller/mail.js
class MailController extends Controller {
  async index() {
    const { app, ctx } = this;
    const { sendmail } = app;
    const to = '[email protected]';
    const data = {
      buyerName: '方跃明',
      statusMsg: '开票成功',
      invoiceDate: '2020-03-10 15:33:32',
      invoiceLine: '电子增值税普通发票',
      invoiceFileUrl: 'https://www.baidu.com',
    };
    const message = {
      subject: '电子发票{{ statusMsg }}',
      html: `**{{ buyerName }},您好:**

您于{{ invoiceDate }}申请的{{ invoiceLine }}{{ statusMsg }},请及时查收。

点击 [此处]({{ invoiceFileUrl }}) 下载电子发票。

若无法下载,请复制以下地址到浏览器中打开:{{ invoiceFileUrl }}`,
    };
    const result = await sendmail.send({ to }, message, data);
    ctx.body = result;
  }
}

module.exports = MailController;

Documents

Please open documents here.

Questions & Suggestions

Please open an issue here.

License

MIT

egg-sendmail's People

Contributors

axolo avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.