add send email api for plugin

This commit is contained in:
xiaoyaofenfen 2022-12-06 20:40:19 +08:00
parent 98de5b931c
commit 695acce3f4
4 changed files with 59 additions and 7 deletions

5
go.mod
View File

@ -7,6 +7,7 @@ require (
github.com/boltdb/bolt v1.3.1 // indirect
github.com/deckarep/golang-set v1.8.0
github.com/dop251/goja v0.0.0-20220408131256-ffe77e20c6f1
github.com/jordan-wright/email v0.0.0-20200602115436-fd8a7622303e // indirect
github.com/json-iterator/go v1.1.12
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@ -16,7 +17,7 @@ require (
github.com/satori/go.uuid v1.2.0
github.com/tickstep/aliyunpan-api v0.1.1
github.com/tickstep/bolt v1.3.3
github.com/tickstep/library-go v0.0.6
github.com/tickstep/library-go v0.0.8
github.com/urfave/cli v1.21.1-0.20190817182405-23c83030263f
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
@ -24,4 +25,4 @@ require (
//replace github.com/tickstep/bolt => /Users/tickstep/Documents/Workspace/go/projects/bolt
//replace github.com/tickstep/library-go => /Users/tickstep/Documents/Workspace/go/projects/library-go
//replace github.com/tickstep/aliyunpan-api => /Users/tickstep/Documents/Workspace/go/projects/aliyunpan-api

8
go.sum
View File

@ -23,6 +23,9 @@ github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/jordan-wright/email v0.0.0-20200602115436-fd8a7622303e h1:OGunVjqY7y4U4laftpEHv+mvZBlr7UGimJXKEGQtg48=
github.com/jordan-wright/email v0.0.0-20200602115436-fd8a7622303e/go.mod h1:Fy2gCFfZhay8jplf/Csj6cyH/oshQTkLQYZbKkcV+SY=
github.com/jordan-wright/email v4.0.0+incompatible/go.mod h1:Fy2gCFfZhay8jplf/Csj6cyH/oshQTkLQYZbKkcV+SY=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
@ -67,13 +70,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tickstep/aliyunpan-api v0.1.1 h1:MRxKpCDhLigoHJANAVXq1K7QphwRGWz+GycDNgOWE1k=
github.com/tickstep/aliyunpan-api v0.1.1/go.mod h1:ZFtMpbmVPM6+zWRTQ7QHw6xzwN/WTm3zaxQjFZ54UAA=
github.com/tickstep/bolt v1.3.3 h1:3abb88T5JJocnBlYTJE3EqKvwWV6+D/JZD2Fsdt1QHI=
github.com/tickstep/bolt v1.3.3/go.mod h1:Y24RwCywbOsKAyHiVcJ4K2QQfED+q67x7PEOH9OG7Q4=
github.com/tickstep/library-go v0.0.5/go.mod h1:egoK/RvOJ3Qs2tHpkq374CWjhNjI91JSCCG1GrhDYSw=
github.com/tickstep/library-go v0.0.6 h1:JkKT2C1RLY6fpH5/vrnhV4pnu1sZS0VhgvJLDYbt608=
github.com/tickstep/library-go v0.0.6/go.mod h1:egoK/RvOJ3Qs2tHpkq374CWjhNjI91JSCCG1GrhDYSw=
github.com/urfave/cli v1.21.1-0.20190817182405-23c83030263f h1:xKDKjIsL76VUyHcA0G4Qe1cIAUB/nrq6Pt8D411bd1g=
github.com/urfave/cli v1.21.1-0.20190817182405-23c83030263f/go.mod h1:qXyCeJubPqsgeiLd3kvHOGHHSrQcNdjZ2ScXIcVZK/I=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View File

@ -1,9 +1,13 @@
package plugins
import (
"crypto/tls"
"github.com/jordan-wright/email"
"github.com/tickstep/library-go/logger"
"github.com/tickstep/library-go/requester"
"net/smtp"
"os"
"strings"
)
// HttpGet Http的get请求
@ -40,3 +44,48 @@ func DeleteLocalFile(localFilePath string) bool {
}
return false
}
func sendEmail(mailServer, userName, password, to, subject, body, mailType string, useSsl bool) error {
mailServerHost := strings.Split(mailServer, ":")[0]
auth := smtp.PlainAuth("", userName, password, mailServerHost)
e := email.NewEmail()
e.From = userName
e.To = []string{to}
e.Subject = subject
if mailType == "html" {
e.HTML = []byte(body)
} else {
e.Text = []byte(body)
}
if useSsl {
return e.SendWithStartTLS(mailServer, auth, &tls.Config{ServerName: mailServerHost, InsecureSkipVerify: true})
} 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
}

View File

@ -8,3 +8,7 @@ import (
func TestDeleteLocalFile(t *testing.T) {
fmt.Println(DeleteLocalFile("/Volumes/Downloads/dev/upload/2"))
}
func TestSendEmail(t *testing.T) {
fmt.Println(sendEmail("smtp.qq.com:465", "111xxx@qq.com", "xxxxxx", "12545xxx@qq.com", "title", "hello", "text", true))
}