Alternative for org.apache.commons.mail.util.MimeMessageParser compatible with Jakarta on Java 17

1.6k Views Asked by At

As I updated my Spring Boot application to Java 17 and Spring Boot 3, I migrated from Java EE to Jakarta. I used the MimeMessageParser of org.apache.commons.mail.util.MimeMessageParser, but it expects a javax.mail.internet.MimeMessage rather than a jakarta.mail.internet.MimeMessage.

I thought there might be an update of org.apache.commons artifact commons-email, but I already use the current version (1.5).

Has someone found a solution how to replace the MimeMessageParser?

2

There are 2 best solutions below

0
S Khandelwal On

Yes, the solution is to remove org.apache.commons artifact commons-email and include group: 'jakarta.mail', name: 'jakarta.mail-api', version: '2.1.2' as dependency.

0
Wouter458 On

Instead of using the javax MimeMessageParser you can use this solution to get the plain text of the message with Jakarta. Just read the bytes of the InputStream and convert it to a String.

 String plainText = new String(mimeMessage.getInputStream().readAllBytes(), StandardCharsets.UTF8);

Related Questions in JAKARTA-MIGRATION