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.

45 lines
1.5 KiB

3 years ago
  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. // @Tags System
  12. // @Summary 发送测试邮件
  13. // @Security ApiKeyAuth
  14. // @Produce application/json
  15. // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
  16. // @Router /email/emailTest [post]
  17. func (s *EmailApi) EmailTest(c *gin.Context) {
  18. if err := service.ServiceGroupApp.EmailTest(); err != nil {
  19. global.GVA_LOG.Error("发送失败!", zap.Error(err))
  20. response.FailWithMessage("发送失败", c)
  21. } else {
  22. response.OkWithData("发送成功", c)
  23. }
  24. }
  25. // @Tags System
  26. // @Summary 发送邮件
  27. // @Security ApiKeyAuth
  28. // @Produce application/json
  29. // @Param data body email_response.Email true "发送邮件必须的参数"
  30. // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
  31. // @Router /email/sendEmail [post]
  32. func (s *EmailApi) SendEmail(c *gin.Context) {
  33. var email email_response.Email
  34. _ = c.ShouldBindJSON(&email)
  35. if err := service.ServiceGroupApp.SendEmail(email.To, email.Subject, email.Body); err != nil {
  36. global.GVA_LOG.Error("发送失败!", zap.Error(err))
  37. response.FailWithMessage("发送失败", c)
  38. } else {
  39. response.OkWithData("发送成功", c)
  40. }
  41. }