diff --git a/docs/manual.md b/docs/manual.md
index 7d7753e..61010de 100644
--- a/docs/manual.md
+++ b/docs/manual.md
@@ -50,6 +50,7 @@
+ [1.禁止特定文件上传](#1.禁止特定文件上传)
+ [2.上传文件后删除本地文件](#2.上传文件后删除本地文件)
+ [3.下载文件并截断过长的文件名](#3.下载文件并截断过长的文件名)
+ + [4.上传文件去掉文件名包含的部分字符](#4.上传文件去掉文件名包含的部分字符)
* [显示和修改程序配置项](#显示和修改程序配置项)
- [常见问题Q&A](#常见问题Q&A)
* [1. 如何获取RefreshToken](#1-如何获取RefreshToken)
@@ -1113,6 +1114,47 @@ console.log("hello world");
PluginUtil.LocalFS.deleteFile(params["localFilePath"]);
```
+5.PluginUtil.Email.sendTextMail()
+发送文本邮件,定义如下
+```
+PluginUtil.Email.sendTextMail(mailServer, userName, password, to, subject, body)
+
+其中:
+mailServer - smtp服务器+端口
+userName - 发件人邮箱地址
+password - 发件人邮箱密码
+to - 收件人邮箱地址
+subject - 邮件标题
+body - 邮件内容,纯文本
+```
+样例
+```js
+PluginUtil.Email.sendTextMail("smtp.qq.com:465", "123xxx@qq.com", "pwdxxxxxx", "12545xxx@qq.com", "文件上传通知", "该文件已经上传完毕");
+```
+
+6.PluginUtil.Email.sendHtmlMail()
+发送HTML富文本邮件,定义如下
+```
+PluginUtil.Email.sendHtmlMail(mailServer, userName, password, to, subject, body)
+
+其中:
+mailServer - smtp服务器+端口
+userName - 发件人邮箱地址
+password - 发件人邮箱密码
+to - 收件人邮箱地址
+subject - 邮件标题
+body - 邮件内容,HTML富文本
+```
+样例
+```js
+var html = ""
+ +"
"
+ +"文件上传通知
"
+ +"该文件已经上传完毕
"
+ +""
+ +"";
+PluginUtil.Email.sendHtmlMail("smtp.qq.com:465", "123xxx@qq.com", "pwdxxxxxx", "12545xxx@qq.com", "文件上传通知", html);
+```
### 常见场景样例
这里收集了一些常见的需求样例,可以作为插件定制的样例模板。
diff --git a/internal/plugins/js_plugin.go b/internal/plugins/js_plugin.go
index 68418fe..f7490b4 100644
--- a/internal/plugins/js_plugin.go
+++ b/internal/plugins/js_plugin.go
@@ -55,6 +55,12 @@ func (js *JsPlugin) Start() error {
pluginObj.Set("LocalFS", localFS)
localFS.Set("deleteFile", DeleteLocalFile) // PluginUtil.LocalFS.deleteFile()
+ // PluginUtil.Email
+ emailObj := js.vm.NewObject()
+ pluginObj.Set("Email", emailObj)
+ emailObj.Set("sendTextMail", SendTextMail) // PluginUtil.Email.sendTextMail()
+ emailObj.Set("sendHtmlMail", SendHtmlMail) // PluginUtil.Email.sendHtmlMail()
+
return nil
}
diff --git a/internal/plugins/plugin_util.go b/internal/plugins/plugin_util.go
index b948da3..904d1d9 100644
--- a/internal/plugins/plugin_util.go
+++ b/internal/plugins/plugin_util.go
@@ -45,6 +45,24 @@ func DeleteLocalFile(localFilePath string) bool {
return false
}
+// SendTextMail 发送文本邮件
+func SendTextMail(mailServer, userName, password, to, subject, body string) bool {
+ if e := sendEmail(mailServer, userName, password, to, subject, body, "text", true); e != nil {
+ logger.Verboseln("js SendTextMail error ", e)
+ return false
+ }
+ return true
+}
+
+// SendHtmlMail 发送HTML富文本邮件
+func SendHtmlMail(mailServer, userName, password, to, subject, body string) bool {
+ if e := sendEmail(mailServer, userName, password, to, subject, body, "html", true); e != nil {
+ logger.Verboseln("js SendHtmlMail error ", e)
+ return false
+ }
+ return true
+}
+
func sendEmail(mailServer, userName, password, to, subject, body, mailType string, useSsl bool) error {
mailServerHost := strings.Split(mailServer, ":")[0]
auth := smtp.PlainAuth("", userName, password, mailServerHost)
@@ -64,28 +82,4 @@ func sendEmail(mailServer, userName, password, to, subject, body, mailType strin
} else {
return e.Send(mailServer, auth)
}
- //
- //// 拼接消息体
- //var contentType string
- //if mailType == "html" {
- // contentType = "Content-Type: text/" + mailType + "; charset=UTF-8"
- //} else {
- // contentType = "Content-Type: text/plain" + "; charset=UTF-8"
- //}
- //msg := []byte("To: " + to + "\r\nFrom: " + userName + "\r\nSubject: " + subject + "\r\n" + contentType + "\r\n\r\n" + body)
- //
- //// msg 内容输出查看
- //logger.Verboseln("To: " + to + "\r\n" +
- // "From: " + userName + "\r\n" +
- // "Subject: " + subject + "\r\n" +
- // "" + contentType + "\r\n\r\n" +
- // "" + body)
- //
- //// 进行身份认证
- //hp := strings.Split(mailServer, ":")
- //auth := smtp.PlainAuth("", userName, password, hp[0])
- //
- //sendTo := strings.Split(to, ";")
- //err := smtp.SendMail(mailServer, auth, userName, sendTo, msg)
- //return err
}