sys_email.go 1.5 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
package api
M
maplepie 已提交
2 3

import (
4 5
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
6
	email_response "github.com/flipped-aurora/gin-vue-admin/server/plugin/email/model/response"
7
	"github.com/flipped-aurora/gin-vue-admin/server/plugin/email/service"
M
maplepie 已提交
8
	"github.com/gin-gonic/gin"
9
	"go.uber.org/zap"
M
maplepie 已提交
10 11
)

Mr.奇淼('s avatar
Mr.奇淼( 已提交
12 13 14
type EmailApi struct {
}

15
// @Tags System
M
maplepie 已提交
16 17 18
// @Summary 发送测试邮件
// @Security ApiKeyAuth
// @Produce  application/json
19
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
M
maplepie 已提交
20
// @Router /email/emailTest [post]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
21 22
func (s *EmailApi) EmailTest(c *gin.Context) {
	if err := service.ServiceGroupApp.EmailTest(); err != nil {
Sliver_Horn's avatar
Sliver_Horn 已提交
23
		global.GVA_LOG.Error("发送失败!", zap.Error(err))
24
		response.FailWithMessage("发送失败", c)
M
maplepie 已提交
25 26 27 28
	} else {
		response.OkWithData("发送成功", c)
	}
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
29 30 31 32 33 34 35 36 37 38 39 40

// @Tags System
// @Summary 发送邮件
// @Security ApiKeyAuth
// @Produce  application/json
// @Param data body email_response.Email true "发送邮件必须的参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /email/sendEmail [post]
func (s *EmailApi) SendEmail(c *gin.Context) {
	var email email_response.Email
	_ = c.ShouldBindJSON(&email)
	if err := service.ServiceGroupApp.SendEmail(email.To, email.Subject, email.Body); err != nil {
Sliver_Horn's avatar
Sliver_Horn 已提交
41
		global.GVA_LOG.Error("发送失败!", zap.Error(err))
Mr.奇淼('s avatar
Mr.奇淼( 已提交
42 43 44 45 46
		response.FailWithMessage("发送失败", c)
	} else {
		response.OkWithData("发送成功", c)
	}
}