mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Notification: attempt to send notifications to all given email addresses (#16881)
Signed-off-by: zhulongcheng <zhulongcheng.me@gmail.com>
This commit is contained in:
parent
f617cd8975
commit
34f6dda6e6
@ -14,6 +14,7 @@ import (
|
||||
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/pkg/errors"
|
||||
gomail "gopkg.in/mail.v2"
|
||||
)
|
||||
|
||||
@ -23,6 +24,7 @@ func (ns *NotificationService) send(msg *Message) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var num int
|
||||
for _, address := range msg.To {
|
||||
m := gomail.NewMessage()
|
||||
m.SetHeader("From", msg.From)
|
||||
@ -34,12 +36,16 @@ func (ns *NotificationService) send(msg *Message) (int, error) {
|
||||
|
||||
m.SetBody("text/html", msg.Body)
|
||||
|
||||
if err := dialer.DialAndSend(m); err != nil {
|
||||
return 0, err
|
||||
e := dialer.DialAndSend(m)
|
||||
if e != nil {
|
||||
err = errors.Wrapf(e, "Failed to send notification to email address: %s", address)
|
||||
continue
|
||||
}
|
||||
|
||||
num += 1
|
||||
}
|
||||
|
||||
return len(msg.To), nil
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (ns *NotificationService) createDialer() (*gomail.Dialer, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user