-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathalert.go
36 lines (28 loc) · 937 Bytes
/
alert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"strings"
gomail "gopkg.in/gomail.v2"
)
func alert(informEmail string, subject string, content []byte,
smtpHost string, smtpPort int, smtpUser string, smtpPassword string) {
m := gomail.NewMessage()
m.SetHeader("From", "[email protected]")
m.SetHeader("To", informEmail)
m.SetHeader("Subject", subject)
c := string(content)
c = strings.Replace(c, "[30m", "", -1)
c = strings.Replace(c, "[31m", "", -1)
c = strings.Replace(c, "[32m", "", -1)
c = strings.Replace(c, "[33m", "", -1)
c = strings.Replace(c, "[34m", "", -1)
c = strings.Replace(c, "[35m", "", -1)
c = strings.Replace(c, "[36m", "", -1)
c = strings.Replace(c, "[37m", "", -1)
c = strings.Replace(c, "[0m", "", -1)
m.SetBody("text/plain", string(content))
d := gomail.NewDialer(smtpHost, smtpPort, smtpUser, smtpPassword)
if err := d.DialAndSend(m); err != nil {
fmt.Printf("failed to send alarm: %v\n", err)
}
}