Grafana - using variables in the "Message" field of Email and other contacts

In the contact point tab i have Choose alertmanager an that is set to Grafana.
Not use if this is shown if you only have one Alertmanager (Grafana)

I guess I do have only one, I have not configured a Prometheus Alertmanager yet

Yes
Be aware thet the name you use for your template must match waht you define in
{{ define "Test2" }}
Otherwise it does not work.

May I please look at your template?

This is how my multy value message looks like.
Name of the template: Template - Multi value
{{ define "Template - Multi value" }}
{{ if gt (len .Alerts.Firing) 0 }}
{{ range .Alerts.Firing }}
*[{{.Status}}] {{ .Labels.Rulename }}*
*[Severity] {{ .Labels.Severity }}*
{{ if gt (len .Annotations) 0 }}
{{ .Annotations.summary }}
{{ .Annotations.description }}
{{ end }}
---------------------------------------------------
{{ end }}
{{ end }}

{{ if gt (len .Alerts.Resolved) 0 }}
Resolved: {{ len .Alerts.Resolved }}
{{ range .Alerts.Resolved }}
*[{{.Status}}] {{ .Labels.Rulename }}*
{{ if gt (len .Annotations) 0 }}
{{ .Annotations.description }}
{{ end }}
---------------------------------------------------
{{ end }}
{{ end }}
{{ end }}

Oh, thanks a lot. Something to start with.

How do you change the Subject of Emails?

what could I be doing wrong here: https://community.grafana.com/t/need-help-using-variables-in-an-email-notification-message/58569/3 why is the template not working as expected?

Can you try this one to see if it works:

Labels:
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
Annotations:
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}
{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}
{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}
{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}
{{ end }}{{ end }}```
Is basically the current default.

I wish I could understand what is wrong with mine:

[{{.Status}}] {{ .Labels.alertname }}
Labels:
{{ range .Labels.SortedPairs }}
{{ .Name }}: {{ .Value }}
{{ end }}
{{ if gt (len .Annotations) 0 }}
Annotations:
{{ range .Annotations.SortedPairs }}
{{ .Name }}: {{ .Value }}
{{ end }}
{{ end }}
{{ end }}```

Maybe they need to be encapsulated by {{ range .Alerts.Firing }} or resolved statments.

> Maybe they need to be encapsulated by {{ range .Alerts.Firing }} or resolved statments.
Maybe they do, it’s not quite obvious from https://grafana.com/docs/grafana/latest/alerting/unified-alerting/message-templating/#custom-template-examples

I always used then in my message bodies.

Thank you for the hint, will try