More flexibile email system.
This commit is contained in:
parent
175d29695e
commit
093bc9af97
12
main.go
12
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,10 +130,11 @@ func fetch() {
|
||||||
log.Fatal("Error opening Rplots.pdf: ", err)
|
log.Fatal("Error opening Rplots.pdf: ", err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
for _, r := range conf.Recipients {
|
||||||
email := mailyak.New(fmt.Sprintf("%s:%d", conf.MailHost, conf.MailPort),
|
email := mailyak.New(fmt.Sprintf("%s:%d", conf.MailHost, conf.MailPort),
|
||||||
smtp.PlainAuth("", conf.Username, conf.Password, conf.MailHost))
|
smtp.PlainAuth("", conf.Username, conf.Password, conf.MailHost))
|
||||||
email.To("gmp@wow.st")
|
email.To(r)
|
||||||
email.From("covid@wow.st")
|
email.From(conf.From)
|
||||||
msg := "Covid dashboard update for " + time.Now().Format("Monday, January 2 2006")
|
msg := "Covid dashboard update for " + time.Now().Format("Monday, January 2 2006")
|
||||||
email.Subject(msg)
|
email.Subject(msg)
|
||||||
email.Plain().Set(msg)
|
email.Plain().Set(msg)
|
||||||
|
@ -139,6 +144,7 @@ func fetch() {
|
||||||
log.Print("Error sending email: ", err)
|
log.Print("Error sending email: ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Printf("starting")
|
log.Printf("starting")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user