email.go 1019 B

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