egg-mail
v1.0.12
Published
Email plugin for egg
Downloads
81
Readme
egg-mail
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:[email protected]*,
}
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','[email protected]');
// or
// sendEmail with attachment
ctx.body = await app.email.sendEmail('Title','Content','Reciver','Attachment');
// ctx.body = await app.email.sendEmail('test','testContent','[email protected]', [ ... ]);
}
};
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.