package notifier import ( "fmt" "log" "net/smtp" "codeberg.org/snonux/gorum/internal/config" ) type email struct { subject, body string } func (em email) send(conf config.Config) error { if !conf.EmailNotifycationEnabled() { return nil } log.Println("notify:", em.subject, em.body) headers := map[string]string{ "From": conf.EmailFrom, "To": conf.EmailTo, "Subject": em.subject, "MIME-Version": "1.0", "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" + em.body log.Println("Using SMTP server", conf.SMTPServer) return smtp.SendMail(conf.SMTPServer, nil, conf.EmailFrom, []string{conf.EmailTo}, []byte(message)) }