diff --git a/pom.xml b/pom.xml
index 6f315ad8f4..98dd6a91e8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,8 +88,9 @@
${jackson.version}
- 2.0.1
3.1.0
+ 2.1.1
+ 2.0.1
6.0.0
3.1.0
4.0.0
@@ -175,7 +176,7 @@
21.5.0.0
- 2.0.0-alpha-3
+ 2.1.0-alpha-1
2.2
2.10
4.13.2
@@ -426,9 +427,15 @@
- com.sun.mail
- jakarta.mail
- ${com.sun.jakarta.mail.version}
+ jakarta.mail
+ jakarta.mail-api
+ ${jakarta.mail.version}
+
+
+
+ org.eclipse.angus
+ angus-mail
+ ${angus.mail.version}
jakarta.ws.rs
diff --git a/quarkus/runtime/pom.xml b/quarkus/runtime/pom.xml
index 0ead7c82bc..aec085780b 100644
--- a/quarkus/runtime/pom.xml
+++ b/quarkus/runtime/pom.xml
@@ -584,8 +584,12 @@
- com.sun.mail
- jakarta.mail
+ jakarta.mail
+ jakarta.mail-api
+
+
+ org.eclipse.angus
+ angus-mail
org.apache.santuario
diff --git a/services/pom.xml b/services/pom.xml
index 75141773f2..088303caa5 100755
--- a/services/pom.xml
+++ b/services/pom.xml
@@ -56,8 +56,12 @@
provided
- com.sun.mail
- jakarta.mail
+ jakarta.mail
+ jakarta.mail-api
+
+
+ org.eclipse.angus
+ angus-mail
org.keycloak
diff --git a/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java b/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java
index 2bbf006e7d..102ae77092 100644
--- a/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java
+++ b/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java
@@ -17,7 +17,7 @@
package org.keycloak.email;
-import com.sun.mail.smtp.SMTPMessage;
+import jakarta.mail.internet.MimeUtility;
import org.jboss.logging.Logger;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.UserModel;
@@ -30,18 +30,23 @@ import jakarta.mail.Address;
import jakarta.mail.MessagingException;
import jakarta.mail.Multipart;
import jakarta.mail.Session;
+import jakarta.mail.Message;
import jakarta.mail.Transport;
import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeBodyPart;
import jakarta.mail.internet.MimeMultipart;
+import jakarta.mail.internet.MimeMessage;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.Map;
import java.util.Properties;
+import static org.keycloak.utils.StringUtil.isNotBlank;
+
/**
* @author Stian Thorgersen
*/
@@ -123,19 +128,21 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider {
multipart.addBodyPart(htmlPart);
}
- SMTPMessage msg = new SMTPMessage(session);
+ Message msg = new MimeMessage(session);
msg.setFrom(toInternetAddress(from, fromDisplayName));
msg.setReplyTo(new Address[]{toInternetAddress(from, fromDisplayName)});
- if (replyTo != null && !replyTo.isEmpty()) {
+
+ if (isNotBlank(replyTo)) {
msg.setReplyTo(new Address[]{toInternetAddress(replyTo, replyToDisplayName)});
}
- if (envelopeFrom != null && !envelopeFrom.isEmpty()) {
- msg.setEnvelopeFrom(envelopeFrom);
+
+ if (isNotBlank(envelopeFrom)) {
+ props.setProperty("mail.smtp.from", envelopeFrom);
}
msg.setHeader("To", address);
- msg.setSubject(subject, "utf-8");
+ msg.setSubject(MimeUtility.encodeText(subject, StandardCharsets.UTF_8.name(), null));
msg.setContent(multipart);
msg.saveChanges();
msg.setSentDate(new Date());
diff --git a/testsuite/utils/pom.xml b/testsuite/utils/pom.xml
index 8dd6f140a9..a47a1dfa3c 100755
--- a/testsuite/utils/pom.xml
+++ b/testsuite/utils/pom.xml
@@ -36,8 +36,12 @@
- com.sun.mail
- jakarta.mail
+ jakarta.mail
+ jakarta.mail-api
+
+
+ org.eclipse.angus
+ angus-mail
org.bouncycastle
@@ -285,7 +289,6 @@
mssql-jdbc
${mssql-jdbc.version}
-