From 4b4066f0f75a4d45ebdb588d61ceb913e4b05bd8 Mon Sep 17 00:00:00 2001 From: Matteo Mara Date: Tue, 15 Feb 2022 17:50:19 +0100 Subject: [PATCH] SONAR-11767 add base url to test emails --- .../notification/email/EmailNotificationChannel.java | 7 ++++++- .../notification/email/EmailNotificationChannelTest.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) 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 2fbc97081b8..7494f673a36 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 @@ -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()); + } + } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java index bad4ca53dfa..e52f4db65d3 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java @@ -114,7 +114,7 @@ public class EmailNotificationChannelTest { assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube from NoWhere "); assertThat(email.getHeader("To", null)).isEqualTo(""); 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 -- 2.39.5