diff --git a/pkg/services/notifications/notifications.go b/pkg/services/notifications/notifications.go index 57c84df8d63..401cd812d5e 100644 --- a/pkg/services/notifications/notifications.go +++ b/pkg/services/notifications/notifications.go @@ -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(), }) diff --git a/pkg/services/notifications/notifications_test.go b/pkg/services/notifications/notifications_test.go index a674d0b14c8..9b9c3ffbf8b 100644 --- a/pkg/services/notifications/notifications_test.go +++ b/pkg/services/notifications/notifications_test.go @@ -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") }) }) diff --git a/public/emails/reset_password.html b/public/emails/reset_password.html index 8753b441c56..970d5da6ca0 100644 --- a/public/emails/reset_password.html +++ b/public/emails/reset_password.html @@ -1,4 +1,4 @@ -{{Subject .Subject "Reset your Grafana password"}} +{{Subject .Subject "Reset your Grafana password - {{.Name}}"}}