From 8dbc61ed030fdc6ee42cc184938a144372b23196 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 4 May 2021 11:43:22 +0100 Subject: [PATCH] dont consider invalid email address a failed email (#33671) (#33681) Signed-off-by: bergquist (cherry picked from commit 06dc2b24bf6c577cfcca1cb31a1d86c9df861b87) Co-authored-by: Carl Bergquist --- pkg/services/notifications/mailer.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/services/notifications/mailer.go b/pkg/services/notifications/mailer.go index 73a897a48f5..9271cc4ff7a 100644 --- a/pkg/services/notifications/mailer.go +++ b/pkg/services/notifications/mailer.go @@ -83,7 +83,13 @@ func (ns *NotificationService) dialAndSend(messages ...*Message) (int, error) { innerError := dialer.DialAndSend(m) emailsSentTotal.Inc() if innerError != nil { - emailsSentFailed.Inc() + // As gomail does not returned typed errors we have to parse the error + // to catch invalid error when the address is invalid. + // https://github.com/go-gomail/gomail/blob/81ebce5c23dfd25c6c67194b37d3dd3f338c98b1/send.go#L113 + if !strings.HasPrefix(innerError.Error(), "gomail: invalid address") { + emailsSentFailed.Inc() + } + err = errutil.Wrapf(innerError, "Failed to send notification to email addresses: %s", strings.Join(msg.To, ";")) continue }