Integrate Jakarta Mail API 2.1.0
This commit is contained in:
parent
acebf4616e
commit
bc43e4f435
5 changed files with 43 additions and 18 deletions
17
pom.xml
17
pom.xml
|
@ -88,8 +88,9 @@
|
|||
<jackson.annotations.version>${jackson.version}</jackson.annotations.version>
|
||||
|
||||
<!--JAKARTA-->
|
||||
<com.sun.jakarta.mail.version>2.0.1</com.sun.jakarta.mail.version>
|
||||
<jakarta.persistence.version>3.1.0</jakarta.persistence.version>
|
||||
<jakarta.mail.version>2.1.1</jakarta.mail.version>
|
||||
<angus.mail.version>2.0.1</angus.mail.version>
|
||||
<jakarta.servlet.version>6.0.0</jakarta.servlet.version>
|
||||
<jakarta.ws.rs.version>3.1.0</jakarta.ws.rs.version>
|
||||
<jakarta.xml.ws.version>4.0.0</jakarta.xml.ws.version>
|
||||
|
@ -175,7 +176,7 @@
|
|||
<oracle-jdbc.version>21.5.0.0</oracle-jdbc.version>
|
||||
|
||||
<!-- Test -->
|
||||
<greenmail.version>2.0.0-alpha-3</greenmail.version>
|
||||
<greenmail.version>2.1.0-alpha-1</greenmail.version>
|
||||
<hamcrest.version>2.2</hamcrest.version>
|
||||
<jmeter.version>2.10</jmeter.version>
|
||||
<junit.version>4.13.2</junit.version>
|
||||
|
@ -426,9 +427,15 @@
|
|||
|
||||
<!--JAKARTA-->
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>jakarta.mail</artifactId>
|
||||
<version>${com.sun.jakarta.mail.version}</version>
|
||||
<groupId>jakarta.mail</groupId>
|
||||
<artifactId>jakarta.mail-api</artifactId>
|
||||
<version>${jakarta.mail.version}</version>
|
||||
</dependency>
|
||||
<!--Implementation of the Jakarta Mail API-->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-mail</artifactId>
|
||||
<version>${angus.mail.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.ws.rs</groupId>
|
||||
|
|
|
@ -584,8 +584,12 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>jakarta.mail</artifactId>
|
||||
<groupId>jakarta.mail</groupId>
|
||||
<artifactId>jakarta.mail-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.santuario</groupId>
|
||||
|
|
|
@ -56,8 +56,12 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>jakarta.mail</artifactId>
|
||||
<groupId>jakarta.mail</groupId>
|
||||
<artifactId>jakarta.mail-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
|
|
|
@ -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 <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
|
@ -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());
|
||||
|
|
|
@ -36,8 +36,12 @@
|
|||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>jakarta.mail</artifactId>
|
||||
<groupId>jakarta.mail</groupId>
|
||||
<artifactId>jakarta.mail-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
|
@ -285,7 +289,6 @@
|
|||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>${mssql-jdbc.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue