发送邮件接口

This commit is contained in:
junleea 2025-10-22 20:22:41 +08:00
parent 66f17ef709
commit 0bf94a0c2b
2 changed files with 5 additions and 0 deletions

View File

@ -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 {

View File

@ -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)