init
commit
9701b3c8d8
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
._*
|
||||||
|
.idea
|
||||||
|
.vscode
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,12 @@
|
||||||
|
![module info](https://nodei.co/npm/@gm5/controller.png?downloads=true&downloadRank=true&stars=true)
|
||||||
|
|
||||||
|
# @gm5/controller
|
||||||
|
|
||||||
|
> 控制器基类。
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @gm5/controller
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
* 邮件收发管理
|
||||||
|
* @author yutent<yutent.io@gmail.com>
|
||||||
|
* @date 2020/09/18 15:59:31
|
||||||
|
*/
|
||||||
|
|
||||||
|
import mailx from 'mailx'
|
||||||
|
|
||||||
|
export default class Sendmail {
|
||||||
|
constructor({ host, port, mail, passwd }) {
|
||||||
|
if (!host || !port || !mail || !passwd) {
|
||||||
|
throw new Error('smtp options [host, port, mail, passwd] is required.')
|
||||||
|
}
|
||||||
|
this.smtp = mailx.transport(host, port, mail, passwd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发件人
|
||||||
|
from(info) {
|
||||||
|
this.mail = mailx.message()
|
||||||
|
this.mail.setFrom(info.name, info.mail)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
// 收件人
|
||||||
|
to(info) {
|
||||||
|
this.mail.addTo(info.name, info.mail)
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送正文
|
||||||
|
send(mail) {
|
||||||
|
this.mail.setSubject(mail.subject)
|
||||||
|
this.mail.setHtml(mail.content)
|
||||||
|
var defer = Promise.defer()
|
||||||
|
this.smtp.send(this.mail, function(err, res) {
|
||||||
|
if (err) {
|
||||||
|
defer.reject(err)
|
||||||
|
} else {
|
||||||
|
defer.resolve(res)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return defer.promise
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "@gm5/mail",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"description": "邮件收发管理",
|
||||||
|
"main": "index.js",
|
||||||
|
"author": "yutent",
|
||||||
|
"keywords": ["fivejs", "controller", "http"],
|
||||||
|
"repository": "https://github.com/bytedo/gmf.mail.git",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
Loading…
Reference in New Issue