From 9701b3c8d89b345d2efb66f8a61a98fa66daab7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 18 Sep 2020 16:04:40 +0800 Subject: [PATCH] init --- .gitignore | 9 +++++++++ LICENSE | 21 +++++++++++++++++++++ Readme.md | 12 ++++++++++++ index.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 11 +++++++++++ 5 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Readme.md create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c24ca8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ + +.Spotlight-V100 +.Trashes +.DS_Store +.AppleDouble +.LSOverride +._* +.idea +.vscode diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ab60297 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..77191b0 --- /dev/null +++ b/Readme.md @@ -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 +``` + diff --git a/index.js b/index.js new file mode 100644 index 0000000..de4f69a --- /dev/null +++ b/index.js @@ -0,0 +1,45 @@ +/** + * 邮件收发管理 + * @author yutent + * @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 + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..7bc214e --- /dev/null +++ b/package.json @@ -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" +}