Set the mail.from to avoid looking up the local hostname

Closes #38353

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2025-04-03 16:53:38 +02:00 committed by GitHub
parent 154206c5f3
commit b62e2f3e8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -115,6 +115,11 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider {
throw new EmailException("No sender address configured in the realm settings for emails");
}
// Specify 'mail.from' as InternetAddress.getLocalAddress() would otherwise do a InetAddress.getCanonicalHostName
// and add this as a mail header. This would both be slow, and would reveal internal IP addresses that we don't want.
// https://jakarta.ee/specifications/mail/2.0/jakarta-mail-spec-2.0#a823
props.setProperty("mail.from", from);
String fromDisplayName = config.get("fromDisplayName");
String replyTo = config.get("replyTo");
String replyToDisplayName = config.get("replyToDisplayName");

View File

@ -31,6 +31,7 @@ import java.util.Locale;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.hamcrest.Matchers;
import org.jboss.arquillian.graphene.page.Page;
import org.junit.Assert;
import org.junit.Rule;
@ -168,6 +169,8 @@ public class EmailTest extends AbstractI18NTest {
MimeMessage message = greenMail.getReceivedMessages()[expectedMsgCount - 1];
assertThat(message.getMessageID(), Matchers.endsWith("@keycloak.org>"));
assertEquals(expectedSubject, message.getSubject());
String textBody = MailUtils.getBody(message).getText();