871893a9d2
- Lists can now be marked as single | double optin. - Insert subscribers to double opt-in lists send out a confirmation e-mail to the subscriber with a confirmation link. - Add `{{ OptinURL }}` to template functions. This is a breaking change. Adds a new field 'optin' to the lists table and changes how campaigns behave. Campaigns on double opt-in lists exclude subscribers who haven't explicitly confirmed subscriptions. Changes the structure and behaviour of how notification e-mail routines, including notif email template compilation, notification callbacks for campaign and bulk import completions.
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
|
|
"github.com/knadh/stuffbin"
|
|
)
|
|
|
|
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.Logger.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.Logger.Printf("error sending admin notification (%s): %v", subject, err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// compileNotifTpls compiles and returns e-mail notification templates that are
|
|
// used for sending ad-hoc notifications to admins and subscribers.
|
|
func compileNotifTpls(path string, fs stuffbin.FileSystem, app *App) (*template.Template, error) {
|
|
// Register utility functions that the e-mail templates can use.
|
|
funcs := template.FuncMap{
|
|
"RootURL": func() string {
|
|
return app.Constants.RootURL
|
|
},
|
|
"LogoURL": func() string {
|
|
return app.Constants.LogoURL
|
|
}}
|
|
|
|
tpl, err := stuffbin.ParseTemplatesGlob(funcs, fs, "/email-templates/*.html")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return tpl, err
|
|
}
|