mirror of
https://github.com/knadh/listmonk.git
synced 2024-11-10 17:13:04 +08:00
8853809713
- Clean up main.go (by moving init to init.go) and improve composition comprehension. - Refactor app context and init struct and field names. - Update package dependencies in initialisation.
39 lines
937 B
Go
39 lines
937 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
)
|
|
|
|
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 sendNotification(toEmails []string, subject, tplName string, data interface{}, app *App) 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.messenger.Push(app.constants.FromEmail,
|
|
toEmails,
|
|
subject,
|
|
b.Bytes(),
|
|
nil)
|
|
if err != nil {
|
|
app.log.Printf("error sending admin notification (%s): %v", subject, err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|