]> source.dussan.org Git - sonarqube.git/commitdiff
Optimize EmailNotificationChannel when SMTP is not configured
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 31 Jul 2018 06:56:35 +0000 (08:56 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 2 Aug 2018 18:21:37 +0000 (20:21 +0200)
No need to load emails of recipients from database if SMTP server
is not configured.

server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java

index 87235eecceb3121a9c3784e601f64326a719496e..d9e68931ceaa6099151228261bb1c8c0fd73d7f6 100644 (file)
@@ -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());