增加邮箱通知

pull/23/head
taoshihan1991 3 years ago
parent 39eab78d3f
commit 8e28291aab

@ -112,6 +112,9 @@ INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL,
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '微信小程序Token', 'WeixinToken', '')|
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '当前小程序审核状态', 'MiniAppAudit', 'yes')|
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '是否允许上传附件', 'SendAttachment', 'true')|
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '发送通知邮件(SMTP地址)', 'NoticeEmailSmtp', '')|
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '发送通知邮件(邮箱)', 'NoticeEmailAddress', '')|
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '发送通知邮件(密码)', 'NoticeEmailPassword', '')|
DROP TABLE IF EXISTS `about`|
CREATE TABLE `about` (

@ -251,7 +251,7 @@ func FolderSend(w http.ResponseWriter, r *http.Request) {
smtpBody := sendData.Body
smtpPass := mailServer.Password
smtpSubject := sendData.Subject
err = tools.Send(smtpServer, smtpFrom, smtpPass, smtpTo, smtpSubject, smtpBody)
err = tools.SendSmtp(smtpServer, smtpFrom, smtpPass, smtpTo, smtpSubject, smtpBody)
if err != nil {
msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: err.Error()})
w.Write(msg)

@ -9,6 +9,7 @@ import (
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"github.com/taoshihan1991/imaptool/ws"
"log"
"os"
"path"
"strconv"
@ -145,6 +146,11 @@ func SendMessageV2(c *gin.Context) {
})
return
}
kefus, ok := ws.KefuList[kefuInfo.Name]
if !ok || len(kefus) == 0 {
log.Println("客服不在线,发送邮件通知")
go SendNoticeEmail(vistorInfo.Name, content)
}
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, content, cType)
var msg TypeMessage
if cType == "kefu" {

@ -22,3 +22,15 @@ func SendServerJiang(content string) string {
res := tools.Get(url)
return res
}
func SendNoticeEmail(username, msg string) {
smtp := models.FindConfig("NoticeEmailSmtp")
email := models.FindConfig("NoticeEmailAddress")
password := models.FindConfig("NoticeEmailPassword")
if smtp == "" || email == "" || password == "" {
return
}
err:=tools.SendSmtp(smtp, email, password, []string{email}, "[通知]"+username, msg)
if err!=nil{
log.Println(err)
}
}

@ -99,6 +99,7 @@ func PostVisitorLogin(c *gin.Context) {
}
models.CreateVisitor(name, avator, c.ClientIP(), toId, id, refer, city, client_ip)
visitor := models.FindVisitorByVistorId(id)
go SendNoticeEmail(visitor.Name, "来了")
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",

@ -1,17 +1,19 @@
package tools
import (
"encoding/base64"
"github.com/emersion/go-sasl"
"github.com/emersion/go-smtp"
"strings"
)
func Send(server string, from string, password string, to []string, subject string, body string) error {
func SendSmtp(server string, from string, password string, to []string, subject string, body string) error {
auth := sasl.NewPlainClient("", from, password)
subjectBase := base64.StdEncoding.EncodeToString([]byte(subject))
msg := strings.NewReader(
"From: " + from + "\r\n" +
"To: " + strings.Join(to, ",") + "\r\n" +
"Subject: " + subject + "\r\n" +
"Subject: =?UTF-8?B?" + subjectBase + "?=\r\n" +
"\r\n" +
body + "\r\n")
err := smtp.SendMail(server, auth, from, to, msg)

Loading…
Cancel
Save