From 9de7b45dbff34a72f8c56fe380bd3d43cdb34e8d Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 31 Jul 2018 08:56:35 +0200 Subject: [PATCH] Optimize EmailNotificationChannel when SMTP is not configured No need to load emails of recipients from database if SMTP server is not configured. --- .../server/notification/email/EmailNotificationChannel.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java index 87235eecceb..d9e68931cea 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java @@ -96,11 +96,17 @@ public class EmailNotificationChannel extends NotificationChannel { @Override public boolean deliver(Notification notification, String username) { + if (StringUtils.isBlank(configuration.getSmtpHost())) { + LOG.debug("SMTP host was not configured - email will not be sent"); + return false; + } + User user = findByLogin(username); if (user == null || StringUtils.isBlank(user.email())) { LOG.debug("User does not exist or has no email: {}", username); return false; } + EmailMessage emailMessage = format(notification); if (emailMessage != null) { emailMessage.setTo(user.email()); -- 2.39.5