Added support for templated email subjects

This commit is contained in:
Torkel Ödegaard 2015-06-14 06:07:36 +02:00
parent fd319bd5f5
commit 9b12350855
3 changed files with 15 additions and 3 deletions

View File

@ -68,10 +68,22 @@ func sendEmailCommandHandler(cmd *m.SendEmailCommand) error {
setDefaultTemplateData(data, nil)
mailTemplates.ExecuteTemplate(&buffer, cmd.Template, data)
subjectTmplText := data["Subject"].(map[string]interface{})["value"].(string)
subjectTmpl, err := template.New("subject").Parse(subjectTmplText)
if err != nil {
return err
}
var subjectBuffer bytes.Buffer
err = subjectTmpl.ExecuteTemplate(&subjectBuffer, "subject", data)
if err != nil {
return err
}
addToMailQueue(&Message{
To: cmd.To,
From: setting.Smtp.FromAddress,
Subject: data["Subject"].(map[string]interface{})["value"].(string),
Subject: subjectBuffer.String(),
Body: buffer.String(),
})

View File

@ -31,7 +31,7 @@ func TestNotifications(t *testing.T) {
err := sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
So(err, ShouldBeNil)
So(sentMsg.Body, ShouldContainSubstring, "body")
So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password")
So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password asd@asd.com")
So(sentMsg.Body, ShouldNotContainSubstring, "Subject")
})
})

View File

@ -1,4 +1,4 @@
{{Subject .Subject "Reset your Grafana password"}}
{{Subject .Subject "Reset your Grafana password - {{.Name}}"}}
<!DOCTYPE html>
<html>