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 = ` 报警通知
%s
不再接收龙弛防溺水报警邮箱通知!
` //查出所有相关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"` }