|
|
|
@ -20,7 +20,8 @@ import (
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Config struct { |
|
|
|
|
MailHost, Username, Password string |
|
|
|
|
MailHost, Username, Password, From string |
|
|
|
|
Recipients []string |
|
|
|
|
MailPort int |
|
|
|
|
Len int64 |
|
|
|
|
} |
|
|
|
@ -52,6 +53,9 @@ func getConf() Config {
|
|
|
|
|
if _, err := toml.DecodeFile(confFile, &conf); err != nil { |
|
|
|
|
log.Fatal("Error reading config file: ", err) |
|
|
|
|
} |
|
|
|
|
if conf.From == "" { |
|
|
|
|
conf.From = conf.Username + "@" + conf.MailHost |
|
|
|
|
} |
|
|
|
|
of, err := os.Create(path.Join(confDir, "c.R")) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatal("Error creating R source file: ", err) |
|
|
|
@ -126,17 +130,19 @@ func fetch() {
|
|
|
|
|
log.Fatal("Error opening Rplots.pdf: ", err) |
|
|
|
|
} |
|
|
|
|
defer f.Close() |
|
|
|
|
email := mailyak.New(fmt.Sprintf("%s:%d", conf.MailHost, conf.MailPort), |
|
|
|
|
smtp.PlainAuth("", conf.Username, conf.Password, conf.MailHost)) |
|
|
|
|
email.To("gmp@wow.st") |
|
|
|
|
email.From("covid@wow.st") |
|
|
|
|
msg := "Covid dashboard update for " + time.Now().Format("Monday, January 2 2006") |
|
|
|
|
email.Subject(msg) |
|
|
|
|
email.Plain().Set(msg) |
|
|
|
|
email.Attach("dashboard.pdf", f) |
|
|
|
|
err = email.Send() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Print("Error sending email: ", err) |
|
|
|
|
for _, r := range conf.Recipients { |
|
|
|
|
email := mailyak.New(fmt.Sprintf("%s:%d", conf.MailHost, conf.MailPort), |
|
|
|
|
smtp.PlainAuth("", conf.Username, conf.Password, conf.MailHost)) |
|
|
|
|
email.To(r) |
|
|
|
|
email.From(conf.From) |
|
|
|
|
msg := "Covid dashboard update for " + time.Now().Format("Monday, January 2 2006") |
|
|
|
|
email.Subject(msg) |
|
|
|
|
email.Plain().Set(msg) |
|
|
|
|
email.Attach("dashboard.pdf", f) |
|
|
|
|
err = email.Send() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Print("Error sending email: ", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|