summaryrefslogtreecommitdiff
path: root/notify.go
diff options
context:
space:
mode:
Diffstat (limited to 'notify.go')
-rw-r--r--notify.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/notify.go b/notify.go
new file mode 100644
index 0000000..c31a242
--- /dev/null
+++ b/notify.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/smtp"
+)
+
+func notify(config config, subject, body string) error {
+ log.Println("emailNotify", subject, body)
+
+ headers := make(map[string]string)
+ headers["From"] = config.EmailFrom
+ headers["To"] = config.EmailTo
+ headers["Subject"] = subject
+ headers["MIME-Version"] = "1.0"
+ headers["Content-Type"] = "text/plain; charset=\"utf-8\""
+
+ header := ""
+ for k, v := range headers {
+ header += fmt.Sprintf("%s: %s\r\n", k, v)
+ }
+
+ message := header + "\r\n" + body
+ log.Println("Using SMTP server", config.SMTPServer)
+ return smtp.SendMail(config.SMTPServer, nil, config.EmailFrom,
+ []string{config.EmailTo}, []byte(message))
+}