Skip to content

lijax/egg-mail

 
 

Repository files navigation

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 = {
  username: *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

About

a plugin for sendEmail of egg

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%