listmonk/notifications.go
Kailash Nadh d4aea0a436 Add support for pushing non-campaign message with workers.
- Refactor campaign.Message into campaign.Message and
  campaign.CampaignMessage
- Remove ad-hoc goroutines (flawed approach) that were used to push
  admin and optin notifications.
- Provision for largscale pushing of ad-hoc, non-campaign messages
  such as transactional messages (in the future).
2020-03-08 12:27:41 +05:30

44 lines
1 KiB
Go

package main
import (
"bytes"
"github.com/knadh/listmonk/internal/manager"
)
const (
notifTplImport = "import-status"
notifTplCampaign = "campaign-status"
notifSubscriberOptin = "subscriber-optin"
notifSubscriberData = "subscriber-data"
)
// notifData represents params commonly used across different notification
// templates.
type notifData struct {
RootURL string
LogoURL string
}
// sendNotification sends out an e-mail notification to admins.
func (app *App) sendNotification(toEmails []string, subject, tplName string, data interface{}) error {
var b bytes.Buffer
if err := app.notifTpls.ExecuteTemplate(&b, tplName, data); err != nil {
app.log.Printf("error compiling notification template '%s': %v", tplName, err)
return err
}
err := app.manager.PushMessage(manager.Message{
From: app.constants.FromEmail,
To: toEmails,
Subject: subject,
Body: b.Bytes(),
Messenger: "email",
})
if err != nil {
app.log.Printf("error sending admin notification (%s): %v", subject, err)
return err
}
return nil
}