From 87c978ebc9ac3d99f21f02b21b2153761015e099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 25 Apr 2017 13:16:37 +0200 Subject: [PATCH] fix: better error handling / messsage when testing email notification when stmp is not configured, fixes #8093 --- pkg/api/alerting.go | 3 +++ pkg/models/notifications.go | 1 + pkg/services/notifications/mailer.go | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 5652196b58c..58ea56cc8a7 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -255,6 +255,9 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R } if err := bus.Dispatch(cmd); err != nil { + if err == models.ErrSmtpNotEnabled { + return ApiError(412, err.Error(), err) + } return ApiError(500, "Failed to send alert notifications", err) } diff --git a/pkg/models/notifications.go b/pkg/models/notifications.go index ad7aed3bc50..089d7c4360d 100644 --- a/pkg/models/notifications.go +++ b/pkg/models/notifications.go @@ -3,6 +3,7 @@ package models import "errors" var ErrInvalidEmailCode = errors.New("Invalid or expired email code") +var ErrSmtpNotEnabled = errors.New("SMTP not configured, check your grafana.ini config file's [smtp] section.") type SendEmailCommand struct { To []string diff --git a/pkg/services/notifications/mailer.go b/pkg/services/notifications/mailer.go index ae1348cbf99..df9f1138b15 100644 --- a/pkg/services/notifications/mailer.go +++ b/pkg/services/notifications/mailer.go @@ -107,7 +107,7 @@ func createDialer() (*gomail.Dialer, error) { func buildEmailMessage(cmd *m.SendEmailCommand) (*Message, error) { if !setting.Smtp.Enabled { - return nil, errors.New("Grafana mailing/smtp options not configured, contact your Grafana admin") + return nil, m.ErrSmtpNotEnabled } var buffer bytes.Buffer