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 {
|
||||
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,10 +130,11 @@ func fetch() {
|
|||
log.Fatal("Error opening Rplots.pdf: ", err)
|
||||
}
|
||||
defer f.Close()
|
||||
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("gmp@wow.st")
|
||||
email.From("covid@wow.st")
|
||||
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)
|
||||
|
@ -138,6 +143,7 @@ func fetch() {
|
|||
if err != nil {
|
||||
log.Print("Error sending email: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user