You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB

  1. package api
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  5. email_response "github.com/flipped-aurora/gin-vue-admin/server/plugin/email/model/response"
  6. "github.com/flipped-aurora/gin-vue-admin/server/plugin/email/service"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. )
  10. type EmailApi struct {
  11. }
  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. if err := service.ServiceGroupApp.EmailTest(); err != nil {
  20. global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
  21. response.FailWithMessage("发送失败", c)
  22. } else {
  23. response.OkWithData("发送成功", c)
  24. }
  25. }
  26. // @Tags System
  27. // @Summary 发送邮件
  28. // @Security ApiKeyAuth
  29. // @Produce application/json
  30. // @Param data body email_response.Email true "发送邮件必须的参数"
  31. // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
  32. // @Router /email/sendEmail [post]
  33. func (s *EmailApi) SendEmail(c *gin.Context) {
  34. var email email_response.Email
  35. _ = c.ShouldBindJSON(&email)
  36. if err := service.ServiceGroupApp.SendEmail(email.To, email.Subject, email.Body); err != nil {
  37. global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
  38. response.FailWithMessage("发送失败", c)
  39. } else {
  40. response.OkWithData("发送成功", c)
  41. }
  42. }