From 06dc2b24bf6c577cfcca1cb31a1d86c9df861b87 Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Tue, 4 May 2021 12:07:50 +0200 Subject: [PATCH] dont consider invalid email address a failed email (#33671) Signed-off-by: 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 b103c432eb6..949f5ec2760 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 }