发送邮件接口
This commit is contained in:
parent
66f17ef709
commit
0bf94a0c2b
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue