From 14165df5123bc86d6cd51f878b19e307e97e00ef Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 27 Aug 2023 17:52:06 +0200 Subject: [PATCH] fix --- server/backend/cron/feedbackEmail.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/backend/cron/feedbackEmail.go b/server/backend/cron/feedbackEmail.go index 29abe6da..71305bc0 100644 --- a/server/backend/cron/feedbackEmail.go +++ b/server/backend/cron/feedbackEmail.go @@ -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") @@ -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 }