Skip to content

Commit

Permalink
Merge pull request #278 from Jinvic/feat/mail
Browse files Browse the repository at this point in the history
fix(mail): 验证邮箱是否为空
  • Loading branch information
xuewenG authored Feb 14, 2025
2 parents 4d2c74e + 5df725e commit 4bda6c8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions backend/handler/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ func (c CommentHandler) AddComment(ctx echo.Context) error {
}
if err = c.commentEmailNotification(comment, frontendHost); err != nil {
c.base.log.Error().Msgf("邮件通知失败,原因:%s", err)
} else {
c.base.log.Info().Msgf("成功发送邮件")
}
}()
return SuccessResp(ctx, h{})
Expand All @@ -235,13 +233,16 @@ func (c CommentHandler) commentEmailNotification(comment db.Comment, host string
return nil
}

// 验证邮箱是否可用
// 验证邮箱是否为空
var targetEmail string
if comment.ReplyTo != "" { // 回复评论
targetEmail = comment.ReplyEmail
} else { // 直接评论
targetEmail = user.Email
}
if targetEmail == "" {
return nil
}

// 获取smtp客户端
client, err := mail.GetSMTPClient(sysConfigVO.SmtpHost, sysConfigVO.SmtpPort, sysConfigVO.SmtpUsername, sysConfigVO.SmtpPassword)
Expand Down Expand Up @@ -300,5 +301,6 @@ func (c CommentHandler) commentEmailNotification(comment db.Comment, host string
return err
}

c.base.log.Info().Msgf("成功发送邮件")
return nil
}

0 comments on commit 4bda6c8

Please sign in to comment.