Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Aug 29, 2023
1 parent 9413600 commit 14165df
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/backend/cron/feedbackEmail.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *CronService) feedbackEmailCron() error {
}
d := gomail.NewDialer(os.Getenv("SMTP_URL"), smtpPort, os.Getenv("SMTP_USERNAME"), os.Getenv("SMTP_PASSWORD"))
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
for _, feedback := range results {
for i, feedback := range results {
m := gomail.NewMessage()
// set message-headers
m.SetAddressHeader("From", os.Getenv("SMTP_USERNAME"), "TUM Campus App")
Expand All @@ -79,14 +79,24 @@ func (c *CronService) feedbackEmailCron() error {
return err
}
m.SetBody("text/plain", txtBodyBuffer.String())
log.Info(txtBodyBuffer.String())

var htmlBodyBuffer bytes.Buffer
if err := parsedHtmlBody.Execute(&htmlBodyBuffer, feedback); err != nil {
return err
}
m.AddAlternative("text/html", htmlBodyBuffer.String())
log.Info(htmlBodyBuffer.String())

// send mail
if err := d.DialAndSend(m); err != nil {
log.WithError(err).Error("could not send mail")
continue
}
log.Trace("sending feedback %d to %s successfull", i, feedback.Receiver)

// prevent the message being send the next time around
if err := c.db.Find(model.Feedback{}, "id = ?", feedback.Id).Update("processed", "true").Error; err != nil {
log.WithError(err).Error("could not prevent mail from being send again")
}
}
return nil
}

0 comments on commit 14165df

Please sign in to comment.