mirror of
https://github.com/grafana/grafana.git
synced 2025-01-02 12:17:01 -06:00
Added support for templated email subjects
This commit is contained in:
parent
fd319bd5f5
commit
9b12350855
@ -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(),
|
||||
})
|
||||
|
||||
|
@ -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")
|
||||
})
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{Subject .Subject "Reset your Grafana password"}}
|
||||
{{Subject .Subject "Reset your Grafana password - {{.Name}}"}}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
Loading…
Reference in New Issue
Block a user