2018-11-28 07:59:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-12-01 12:18:36 +00:00
|
|
|
notifTplImport = "import-status"
|
|
|
|
notifTplCampaign = "campaign-status"
|
|
|
|
notifSubscriberOptin = "subscriber-optin"
|
|
|
|
notifSubscriberData = "subscriber-data"
|
2018-11-28 07:59:57 +00:00
|
|
|
)
|
|
|
|
|
2019-12-01 12:18:36 +00:00
|
|
|
// notifData represents params commonly used across different notification
|
|
|
|
// templates.
|
|
|
|
type notifData struct {
|
|
|
|
RootURL string
|
|
|
|
LogoURL string
|
|
|
|
}
|
2018-11-28 07:59:57 +00:00
|
|
|
|
2019-12-01 12:18:36 +00:00
|
|
|
// sendNotification sends out an e-mail notification to admins.
|
|
|
|
func sendNotification(toEmails []string, subject, tplName string, data interface{}, app *App) error {
|
2018-11-28 07:59:57 +00:00
|
|
|
var b bytes.Buffer
|
2020-03-07 18:33:22 +00:00
|
|
|
if err := app.notifTpls.ExecuteTemplate(&b, tplName, data); err != nil {
|
|
|
|
app.log.Printf("error compiling notification template '%s': %v", tplName, err)
|
2018-11-28 07:59:57 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-07 18:33:22 +00:00
|
|
|
err := app.messenger.Push(app.constants.FromEmail,
|
2019-12-01 12:18:36 +00:00
|
|
|
toEmails,
|
2018-11-28 07:59:57 +00:00
|
|
|
subject,
|
2019-07-18 07:10:48 +00:00
|
|
|
b.Bytes(),
|
|
|
|
nil)
|
2018-11-28 07:59:57 +00:00
|
|
|
if err != nil {
|
2020-03-07 18:33:22 +00:00
|
|
|
app.log.Printf("error sending admin notification (%s): %v", subject, err)
|
2018-11-28 07:59:57 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|