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