HFish/view/mail/view.go

44 lines
917 B
Go
Raw Normal View History

2019-08-07 13:16:23 +08:00
package mail
import (
"github.com/gin-gonic/gin"
"net/http"
"strings"
"HFish/core/dbUtil"
"HFish/utils/send"
"HFish/error"
2019-08-12 10:42:23 +08:00
"strconv"
2019-08-07 13:16:23 +08:00
)
func Html(c *gin.Context) {
c.HTML(http.StatusOK, "mail.html", gin.H{})
}
/*发送邮件*/
func SendEmailToUsers(c *gin.Context) {
emails := c.PostForm("emails")
title := c.PostForm("title")
2019-08-25 20:06:38 +08:00
//from := c.PostForm("from")
2019-08-07 13:16:23 +08:00
content := c.PostForm("content")
eArr := strings.Split(emails, ",")
sql := `select status,info from hfish_setting where type = "mail"`
isAlertStatus := dbUtil.Query(sql)
info := isAlertStatus[0]["info"]
config := strings.Split(info.(string), "&&")
2019-08-25 20:06:38 +08:00
//if from != "" {
// config[2] = from
//}
2019-08-07 13:16:23 +08:00
2019-08-12 10:42:23 +08:00
status := strconv.FormatInt(isAlertStatus[0]["status"].(int64), 10)
if status == "1" {
send.SendMail(eArr, title, content, config)
c.JSON(http.StatusOK, error.ErrSuccessNull())
} else {
c.JSON(http.StatusOK, error.ErrEmailFail())
}
2019-08-07 13:16:23 +08:00
}