email.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package eventServer
  2. import (
  3. "fmt"
  4. "github.com/sirupsen/logrus"
  5. mail "github.com/xhit/go-simple-mail/v2"
  6. "lcfns/global"
  7. "lcfns/utils"
  8. )
  9. func SendAlarmEmail(cameraMac string, msg string, file *mail.File) {
  10. var html = `
  11. <!DOCTYPE html>
  12. <html>
  13. <head><title>报警通知</title></head>
  14. <body>
  15. <h5>%s</h5>
  16. <h5><a href="http://192.168.110.69:8889/user/userUnbindEmail?id=%d&email=%s">不再接收龙弛防溺水报警邮箱通知!</a></h5>
  17. </body>
  18. </html>
  19. `
  20. //查出所有相关email
  21. var emails []UserEmails
  22. //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';
  23. err := global.Db.Select("g.uid,e.email").
  24. Table("camera c JOIN gateway g ON c.gid = g.id LEFT JOIN sys_user_email e ON g.uid = e.uid").
  25. Where("c.mac_address = ?", cameraMac).
  26. Scan(&emails).Error
  27. if err != nil {
  28. logrus.Error(err)
  29. return
  30. }
  31. for _, v := range emails {
  32. body := fmt.Sprintf(html, msg, v.Uid, v.Email)
  33. utils.EmailPicture(v.Email,
  34. "防溺水通知",
  35. body,
  36. file)
  37. }
  38. }
  39. type UserEmails struct {
  40. Uid uint `json:"uid"`
  41. Email string `json:"email"`
  42. }