zhangqian
2023-08-26 5193dcb9336e853502baf8a539d3f45efebe2f86
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package api
 
import (
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "srm/global"
    "srm/model/common/response"
    email_response "srm/plugin/email/model/response"
    "srm/plugin/email/service"
)
 
type EmailApi struct{}
 
// EmailTest
// @Tags      System
// @Summary   发送测试邮件
// @Security  ApiKeyAuth
// @Produce   application/json
// @Success   200  {string}  string  "{"success":true,"data":{},"msg":"发送成功"}"
// @Router    /email/emailTest [post]
func (s *EmailApi) EmailTest(c *gin.Context) {
    err := service.ServiceGroupApp.EmailTest()
    if err != nil {
        global.GVA_LOG.Error("发送失败!", zap.Error(err))
        response.FailWithMessage("发送失败", c)
        return
    }
    response.OkWithMessage("发送成功", c)
}
 
// SendEmail
// @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
    err := c.ShouldBindJSON(&email)
    if err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    err = service.ServiceGroupApp.SendEmail(email.To, email.Subject, email.Body)
    if err != nil {
        global.GVA_LOG.Error("发送失败!", zap.Error(err))
        response.FailWithMessage("发送失败", c)
        return
    }
    response.OkWithMessage("发送成功", c)
}