发送邮件接口
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 err := c.ShouldBind(&req); err == nil {
|
||||||
//发送邮件
|
//发送邮件
|
||||||
if user.Role == "admin" {
|
if user.Role == "admin" {
|
||||||
|
log.Println("send mail req:", req)
|
||||||
go service.SendEmail(req.To, req.Title, req.Content)
|
go service.SendEmail(req.To, req.Title, req.Content)
|
||||||
resp.Code, resp.Data, resp.Message = proto.SuccessCode, "mail will be sent", "success"
|
resp.Code, resp.Data, resp.Message = proto.SuccessCode, "mail will be sent", "success"
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,10 @@ func SendEmail(email, subject, body string) {
|
||||||
em.SmtpUserName = "354425203@qq.com"
|
em.SmtpUserName = "354425203@qq.com"
|
||||||
em.SmtpPort = 587
|
em.SmtpPort = 587
|
||||||
em.ImapPort = 993
|
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})
|
err := em.Send(subject, body, []string{email})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("send mail error:", err)
|
fmt.Println("send mail error:", err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue