From f7456fded178b85637c82255e9c3178817f5fa68 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 17 Apr 2023 19:47:08 +0300 Subject: initial version --- notify.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 notify.go (limited to 'notify.go') 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)) +} -- cgit v1.2.3