From 6a1ee77dcfc931457a97b906245483f62529c1e2 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Tue, 6 Nov 2018 08:52:20 +0530 Subject: [PATCH] Fixed message rendering in test messages --- campaigns.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/campaigns.go b/campaigns.go index f5a3c6b..0af1d05 100644 --- a/campaigns.go +++ b/campaigns.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "database/sql" "errors" "fmt" @@ -13,7 +12,6 @@ import ( "github.com/asaskevich/govalidator" "github.com/knadh/listmonk/models" - "github.com/knadh/listmonk/runner" "github.com/labstack/echo" "github.com/lib/pq" 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. - var out = bytes.Buffer{} - if err := camp.Tpl.ExecuteTemplate(&out, - runner.BaseTPL, - runner.Message{Campaign: camp, Subscriber: sub, UnsubscribeURL: "#dummy"}); err != nil { - return fmt.Errorf("Error executing template: %v", err) + m := app.Runner.NewMessage(camp, sub) + if err := m.Render(); err != nil { + return echo.NewHTTPError(http.StatusBadRequest, + fmt.Sprintf("Error rendering message: %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 }