]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11767 add base url to test emails
authorMatteo Mara <matteo.mara@sonarsource.com>
Tue, 15 Feb 2022 16:50:19 +0000 (17:50 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 17 Feb 2022 20:03:22 +0000 (20:03 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java

index 2fbc97081b84f8e965ee4c94fe272750e49b4851..7494f673a36895f4b7e650bf272e829e4f9c6a15 100644 (file)
@@ -91,6 +91,7 @@ public class EmailNotificationChannel extends NotificationChannel {
 
   private static final String SUBJECT_DEFAULT = "Notification";
   private static final String SMTP_HOST_NOT_CONFIGURED_DEBUG_MSG = "SMTP host was not configured - email will not be sent";
+  private static final String MAIL_SENT_FROM = "%sMail sent from: %s";
 
   private final EmailSettings configuration;
   private final EmailTemplate[] templates;
@@ -333,7 +334,7 @@ public class EmailNotificationChannel extends NotificationChannel {
       EmailMessage emailMessage = new EmailMessage();
       emailMessage.setTo(toAddress);
       emailMessage.setSubject(subject);
-      emailMessage.setPlainTextMessage(message);
+      emailMessage.setPlainTextMessage(message + getServerBaseUrlFooter());
       send(emailMessage);
     } catch (EmailException e) {
       LOG.debug("Fail to send test email to {}: {}", toAddress, e);
@@ -341,4 +342,8 @@ public class EmailNotificationChannel extends NotificationChannel {
     }
   }
 
+  private String getServerBaseUrlFooter() {
+    return String.format(MAIL_SENT_FROM, "\n\n", configuration.getServerBaseURL());
+  }
+
 }
index bad4ca53dfa461b86933f3f5b5767ba7688867c7..e52f4db65d3a40d27453165282d6495edd3fb9ad 100644 (file)
@@ -114,7 +114,7 @@ public class EmailNotificationChannelTest {
     assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube from NoWhere <server@nowhere>");
     assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>");
     assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Test Message from SonarQube");
-    assertThat((String) email.getContent()).startsWith("This is a test message from SonarQube.");
+    assertThat((String) email.getContent()).startsWith("This is a test message from SonarQube.\r\n\r\nMail sent from: http://nemo.sonarsource.org");
   }
 
   @Test