https://github.com/zhouzhi3859/egg-mail
a plugin for sendEmail of egg
https://github.com/zhouzhi3859/egg-mail
egg egg-mail egg-plugin
Last synced: 8 months ago
JSON representation
a plugin for sendEmail of egg
- Host: GitHub
- URL: https://github.com/zhouzhi3859/egg-mail
- Owner: zhouzhi3859
- License: mit
- Created: 2017-11-02T08:08:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-26T09:39:41.000Z (about 7 years ago)
- Last Synced: 2025-02-01T16:48:02.253Z (over 1 year ago)
- Topics: egg, egg-mail, egg-plugin
- Language: JavaScript
- Size: 26.4 KB
- Stars: 10
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-mail

[](https://nodejs.org/en/)
[](https://www.npmjs.com/)

[](https://www.travis-ci.org/zhouzhi3859/egg-mail)
Email smtp client based on emailjs for egg framework
## Install
```bash
$ npm i egg-mail --save
```
Email Plugin for egg, support egg application send email.
This plugin based on [emailjs](https://github.com/eleith/emailjs)
## Configuration
Change `${app_root}/config/plugin.js` to enable email plugin:
```js
exports.email = {
enable: true,
package: 'egg-mail',
};
```
Configure email information in `${app_root}/config/config.default.js`:
**Single Client**
```js
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.
```js
// 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:"i hope this works!", alternative:true},
{path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"}
]
```
more detail please click [here](https://github.com/eleith/emailjs#example-usage---html-emails-and-attachments)
## Questions & Suggestions
Please open an issue [here](https://github.com/zhouzhi3859/egg-mail/issues).
## Typescript
you can visit this [example](https://github.com/zhouzhi3859/iMagazineServerTS).
## License
[MIT](LICENSE)