1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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 = `
- <!DOCTYPE html>
- <html>
- <head><title>报警通知</title></head>
- <body>
- <h5>%s</h5>
- <h5><a href="http://192.168.110.165:9000/user/userUnbindEmail?id=%d&email=%s">不再接收龙弛防防盗砂报警邮箱通知!</a></h5>
- </body>
- </html>
- `
- //查出所有相关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"`
- }
|