diff --git a/handler/tool.go b/handler/tool.go index 6131452..5a506ae 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -471,6 +471,7 @@ func SendMailTool(c *gin.Context) { if err := c.ShouldBind(&req); err == nil { //发送邮件 if user.Role == "admin" { + log.Println("send mail req:", req) go service.SendEmail(req.To, req.Title, req.Content) resp.Code, resp.Data, resp.Message = proto.SuccessCode, "mail will be sent", "success" } else { diff --git a/service/toolService.go b/service/toolService.go index c6da1ab..e22379b 100644 --- a/service/toolService.go +++ b/service/toolService.go @@ -104,6 +104,10 @@ func SendEmail(email, subject, body string) { em.SmtpUserName = "354425203@qq.com" em.SmtpPort = 587 em.ImapPort = 993 + if email == "" || subject == "" || body == "" { + log.Println("tool send email fail: email or subject or body is empty") + return + } err := em.Send(subject, body, []string{email}) if err != nil { fmt.Println("send mail error:", err)