sys_email.go 1.5 KB

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