Fix email From configuration
This commit is contained in:
parent
cadae2a9e5
commit
2a879f649f
|
@ -118,7 +118,6 @@ func (c *EmailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
if c.To == "" {
|
||||
return fmt.Errorf("missing to address in email config")
|
||||
}
|
||||
|
||||
// Header names are case-insensitive, check for collisions.
|
||||
normalizedHeaders := map[string]string{}
|
||||
for h, v := range c.Headers {
|
||||
|
@ -129,15 +128,6 @@ func (c *EmailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
normalizedHeaders[normalized] = v
|
||||
}
|
||||
c.Headers = normalizedHeaders
|
||||
if _, ok := c.Headers["Subject"]; !ok {
|
||||
c.Headers["Subject"] = DefaultEmailSubject
|
||||
}
|
||||
if _, ok := c.Headers["To"]; !ok {
|
||||
c.Headers["To"] = c.To
|
||||
}
|
||||
if _, ok := c.Headers["From"]; !ok {
|
||||
c.Headers["From"] = c.From
|
||||
}
|
||||
|
||||
return checkOverflow(c.XXX, "email config")
|
||||
}
|
||||
|
|
|
@ -128,6 +128,15 @@ type Email struct {
|
|||
|
||||
// NewEmail returns a new Email notifier.
|
||||
func NewEmail(c *config.EmailConfig, t *template.Template) *Email {
|
||||
if _, ok := c.Headers["Subject"]; !ok {
|
||||
c.Headers["Subject"] = config.DefaultEmailSubject
|
||||
}
|
||||
if _, ok := c.Headers["To"]; !ok {
|
||||
c.Headers["To"] = c.To
|
||||
}
|
||||
if _, ok := c.Headers["From"]; !ok {
|
||||
c.Headers["From"] = c.From
|
||||
}
|
||||
return &Email{conf: c, tmpl: t}
|
||||
}
|
||||
|
||||
|
@ -229,8 +238,8 @@ func (n *Email) Notify(ctx context.Context, as ...*types.Alert) error {
|
|||
}
|
||||
defer wc.Close()
|
||||
|
||||
for header, name := range n.conf.Headers {
|
||||
value, err := n.tmpl.ExecuteTextString(name, data)
|
||||
for header, t := range n.conf.Headers {
|
||||
value, err := n.tmpl.ExecuteTextString(t, data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("executing %q header template: %s", header, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue