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:
exportsemail = enable: true package: 'egg-mail';
Configure email information in ${app_root}/config/config.default.js
:
Single Client
configemail = 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 emaillike:XXX@XXXcom*
Usage
In controller, you can use app.email.sendEmail
to send email.
// app/controller/home.jsconst Controller = Controller; async { const ctx app = this; // sendEmail ctxbody = await appemail; // ctx.body = await app.email.sendEmail('test','testContent','test@test.com'); // or // sendEmail with attachment ctxbody = await appemail; // ctx.body = await app.email.sendEmail('test','testContent','test@test.com', [ ... ]); };moduleexports = 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.