package eventServer
import (
"fmt"
"github.com/sirupsen/logrus"
mail "github.com/xhit/go-simple-mail/v2"
"lc-fangdaosha/global"
"lc-fangdaosha/utils"
)
func SendAlarmEmail(cameraMac string, msg string, file *mail.File) {
var html = `
报警通知
%s
`
//查出所有相关email
var emails []UserEmails
err := global.Db.Select("g.uid,e.email").
Table("camera c JOIN gateway g ON c.gid = g.id LEFT JOIN sys_user_email e ON g.uid = e.uid").
Where("c.mac_address = ?", cameraMac).
Scan(&emails).Error
if err != nil {
logrus.Error(err)
return
}
for _, v := range emails {
body := fmt.Sprintf(html, msg, v.Uid, v.Email)
utils.EmailPicture(v.Email,
"防盗砂通知",
body,
file)
}
}
type UserEmails struct {
Uid uint `json:"uid"`
Email string `json:"email"`
}