egg-mail
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

egg-mail

Build Status

Email smtp client based on emailjs for egg framework

Install

$ npm i egg-mail --save

Email Plugin for egg, support egg application send email.

This plugin based on emailjs

Configuration

Change ${app_root}/config/plugin.js to enable email plugin:

exports.email = {
  enable: true,
  package: 'egg-mail',
};

Configure email information in ${app_root}/config/config.default.js:

Single Client

config.email = {
  user: *your email account*,
  password: *your email password*,
  host: *you email smtp server ip or domain name*,
  sender: *what accout are you use to send email,like:XXX@XXX.com*,
}

Usage

In controller, you can use app.email.sendEmail to send email.

// app/controller/home.js
const Controller = require('egg').Controller;
class HomeController extends Controller {
  async index() {
    const { ctx, app } = this;
    // sendEmail
    ctx.body = await app.email.sendEmail('Title','Content','Reciver');
    // ctx.body = await app.email.sendEmail('test','testContent','test@test.com');
    // or
    // sendEmail with attachment
    ctx.body = await app.email.sendEmail('Title','Content','Reciver','Attachment');
    // ctx.body = await app.email.sendEmail('test','testContent','test@test.com', [ ... ]);
  }
};
module.exports = HomeController;

Example Attachment Array

[
  {data:"<html>i <i>hope</i> this works!</html>", alternative:true},
  {path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"}
]

more detail please click here

Questions & Suggestions

Please open an issue here.

Typescript

you can visit this example.

License

MIT

Package Sidebar

Install

npm i egg-mail

Weekly Downloads

28

Version

1.0.12

License

MIT

Unpacked Size

6.87 kB

Total Files

11

Last publish

Collaborators

  • zhouzhi