summaryrefslogtreecommitdiff
path: root/notifications.go
diff options
context:
space:
mode:
authorJan Dittberner <jandd@cacert.org>2021-02-28 18:25:17 +0100
committerJan Dittberner <jandd@cacert.org>2021-03-07 19:42:11 +0100
commit70cc0942ca017007d5da66870fa20185fd8fbbaa (patch)
treea4a68fc5dc302b2f337db32f7c909049533c6706 /notifications.go
parent03827874cfc51b4be6709459d5263ef87f31dbe4 (diff)
downloadcacert-boardvoting-70cc0942ca017007d5da66870fa20185fd8fbbaa.tar.gz
cacert-boardvoting-70cc0942ca017007d5da66870fa20185fd8fbbaa.tar.xz
cacert-boardvoting-70cc0942ca017007d5da66870fa20185fd8fbbaa.zip
Upgrade to Go 1.16 and newer libraries
- use embed from the standard library instead of packr - upgrade to sprig v3 - upgrade gomail version - use golang-migrate instead of sql-migrate to get embed support - use statigz to deliver compressed static assets
Diffstat (limited to 'notifications.go')
-rw-r--r--notifications.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/notifications.go b/notifications.go
index 49fc543..59ba9d5 100644
--- a/notifications.go
+++ b/notifications.go
@@ -18,13 +18,12 @@ package main
import (
"bytes"
+ "embed"
"fmt"
"text/template"
- "github.com/Masterminds/sprig"
- "gopkg.in/gomail.v2"
-
- "git.cacert.org/cacert-boardvoting/boardvoting"
+ "github.com/Masterminds/sprig/v3"
+ "github.com/go-mail/mail"
log "github.com/sirupsen/logrus"
)
@@ -69,7 +68,7 @@ func MailNotifier(quitMailNotifier chan int) {
continue
}
- m := gomail.NewMessage()
+ m := mail.NewMessage()
m.SetAddressHeader("From", config.NotificationSenderAddress, "CAcert board voting system")
for _, recipient := range content.recipients {
@@ -84,7 +83,7 @@ func MailNotifier(quitMailNotifier chan int) {
m.SetBody("text/plain", mailText.String())
- d := gomail.NewDialer(config.MailServer.Host, config.MailServer.Port, "", "")
+ d := mail.NewDialer(config.MailServer.Host, config.MailServer.Port, "", "")
if err := d.DialAndSend(m); err != nil {
log.Errorf("sending mail failed: %v", err)
}
@@ -96,8 +95,11 @@ func MailNotifier(quitMailNotifier chan int) {
}
}
+//go:embed boardvoting/templates
+var mailTemplates embed.FS
+
func buildMail(templateName string, context interface{}) (mailText *bytes.Buffer, err error) {
- b, err := boardvoting.Asset(fmt.Sprintf("templates/%s", templateName))
+ b, err := mailTemplates.ReadFile(fmt.Sprintf("templates/%s", templateName))
if err != nil {
return
}