Fixed message rendering in test messages

This commit is contained in:
Kailash Nadh 2018-11-06 08:52:20 +05:30
parent f334022cd6
commit 6a1ee77dcf
1 changed files with 5 additions and 8 deletions

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"bytes"
"database/sql" "database/sql"
"errors" "errors"
"fmt" "fmt"
@ -13,7 +12,6 @@ import (
"github.com/asaskevich/govalidator" "github.com/asaskevich/govalidator"
"github.com/knadh/listmonk/models" "github.com/knadh/listmonk/models"
"github.com/knadh/listmonk/runner"
"github.com/labstack/echo" "github.com/labstack/echo"
"github.com/lib/pq" "github.com/lib/pq"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
@ -471,14 +469,13 @@ func sendTestMessage(sub *models.Subscriber, camp *models.Campaign, app *App) er
} }
// Render the message body. // Render the message body.
var out = bytes.Buffer{} m := app.Runner.NewMessage(camp, sub)
if err := camp.Tpl.ExecuteTemplate(&out, if err := m.Render(); err != nil {
runner.BaseTPL, return echo.NewHTTPError(http.StatusBadRequest,
runner.Message{Campaign: camp, Subscriber: sub, UnsubscribeURL: "#dummy"}); err != nil { fmt.Sprintf("Error rendering message: %v", err))
return fmt.Errorf("Error executing template: %v", err)
} }
if err := app.Messenger.Push(camp.FromEmail, sub.Email, camp.Subject, []byte(out.Bytes())); err != nil { if err := app.Messenger.Push(camp.FromEmail, sub.Email, camp.Subject, m.Body); err != nil {
return err return err
} }