奇淼(piexlmax
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 186 additions and 3 deletions
-
23server/api/v1/sys_email.go
-
13server/config.yaml
-
11server/config/config.go
-
1server/go.mod
-
1server/initialize/router.go
-
14server/router/sys_email.go
-
17server/service/sys_email.go
-
50server/utils/email.go
-
15web/src/api/email.js
-
44web/src/view/systemTools/system/system.vue
@ -0,0 +1,23 @@ |
|||
package v1 |
|||
|
|||
import ( |
|||
"fmt" |
|||
"gin-vue-admin/global/response" |
|||
"gin-vue-admin/service" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// @Tags system
|
|||
// @Summary 发送测试邮件
|
|||
// @Security ApiKeyAuth
|
|||
// @Produce application/json
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
|||
// @Router /email/emailTest [post]
|
|||
func EmailTest(c *gin.Context) { |
|||
err := service.EmailTest() |
|||
if err != nil { |
|||
response.FailWithMessage(fmt.Sprintf("发送失败,%v", err), c) |
|||
} else { |
|||
response.OkWithData("发送成功", c) |
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
package router |
|||
|
|||
import ( |
|||
"gin-vue-admin/api/v1" |
|||
"gin-vue-admin/middleware" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
func InitEmailRouter(Router *gin.RouterGroup) { |
|||
UserRouter := Router.Group("email").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) |
|||
{ |
|||
UserRouter.POST("emailTest", v1.EmailTest) // 发送测试邮件
|
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
package service |
|||
|
|||
import ( |
|||
"gin-vue-admin/utils" |
|||
) |
|||
|
|||
// @title EmailTest
|
|||
// @description 发送邮件测试
|
|||
// @auth (2020/09/08 13:58
|
|||
// @return err error
|
|||
|
|||
func EmailTest() (err error) { |
|||
subject := "test" |
|||
body := "test" |
|||
err = utils.EmailTest(subject, body) |
|||
return err |
|||
} |
@ -0,0 +1,50 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"fmt" |
|||
"strings" |
|||
"net/smtp" |
|||
"crypto/tls" |
|||
|
|||
"gin-vue-admin/global" |
|||
|
|||
"github.com/jordan-wright/email" |
|||
) |
|||
|
|||
func Email(subject string, body string) error { |
|||
to := strings.Split(global.GVA_CONFIG.Email.EmailTo, ",") |
|||
return send(to, subject, body) |
|||
} |
|||
|
|||
func EmailTest(subject string, body string) error { |
|||
to := []string{global.GVA_CONFIG.Email.EmailFrom} |
|||
return send(to, subject, body) |
|||
} |
|||
|
|||
func send(to []string, subject string, body string) error { |
|||
from := global.GVA_CONFIG.Email.EmailFrom |
|||
nickName := global.GVA_CONFIG.Email.EmailNickName |
|||
secret := global.GVA_CONFIG.Email.EmailSecret |
|||
host := global.GVA_CONFIG.Email.EmailHost |
|||
port := global.GVA_CONFIG.Email.EmailPort |
|||
isSSL := global.GVA_CONFIG.Email.EmailIsSSL |
|||
|
|||
auth := smtp.PlainAuth("", from, secret, host) |
|||
e := email.NewEmail() |
|||
if nickName == "" { |
|||
e.From = fmt.Sprintf("%s <%s>", nickName, from) |
|||
}else{ |
|||
e.From = from |
|||
} |
|||
e.To = to |
|||
e.Subject = subject |
|||
e.HTML = []byte(body) |
|||
var err error |
|||
hostAddr := fmt.Sprintf("%s:%d", host, port) |
|||
if isSSL { |
|||
err = e.SendWithTLS(hostAddr, auth, &tls.Config{ServerName: host}) |
|||
}else{ |
|||
err = e.Send(hostAddr, auth) |
|||
} |
|||
return err |
|||
} |
@ -0,0 +1,15 @@ |
|||
import service from '@/utils/request' |
|||
|
|||
// @Tags email
|
|||
// @Summary 发送测试邮件
|
|||
// @Security ApiKeyAuth
|
|||
// @Produce application/json
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
|||
// @Router /email/emailTest [post]
|
|||
export const emailTest = (data) => { |
|||
return service({ |
|||
url: "/email/emailTest", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue