123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package eventServer
- import (
- "fmt"
- "github.com/sirupsen/logrus"
- mail "github.com/xhit/go-simple-mail/v2"
- "lcfns/global"
- "lcfns/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.69:8889/user/userUnbindEmail?id=%d&email=%s">不再接收龙弛防溺水报警邮箱通知!</a></h5>
- </body>
- </html>
- `
- //查出所有相关email
- var emails []UserEmails
- //SELECT e.email FROM 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 = 'e0:ca:3c:6a:26:8c';
- 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"`
- }
|