Issue
I'd like to write some tests for particuar classes. Yet, I want to read in an EML file. This works fine by using
IOUtils.toString(r.getInputStream(), StandardCharsets.UTF_8);
I have a class which is (normally) able to read such an EML (by InputStream, filename or file content(String)) what is done so far in multiple places in the project. When I try to do this in a test class I get this:
java.lang.NoSuchMethodError: 'boolean com.sun.mail.util.PropUtil.getBooleanSessionProperty(javax.mail.Session, java.lang.String, boolean)'
at javax.mail.internet.MimeMessage.initStrict(MimeMessage.java:320)
at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:215)
at d.d.a.c.e.EmlFileHolder.buildByEmlFile(EmlFileHolder.java:103)
at d.d.a.c.e.EmlFileHolder.buildByEmlFileStream(EmlFileHolder.java:99)
at d.d.a.c.e.EmlFileHolder.buildByEmlFileString(EmlFileHolder.java:81)
Maybe a problem with the dependencies? (But I couldn't solve or even figure out the problem.) Here, the imported dependencies related to mail, MimeMessages, ...
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>${simple-java-mail.version}</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>smime-module</artifactId>
<version>${simple-java-mail.version}</version>
</dependency>
Solution
You appear to be mixing code that uses the old javax.mail.*
APIs (and thus com.sun.mail.*
) with the new jakarta.mail
2.0 API and implementation.
I suspect you managed this by updating to jakarta.mail
in the POM but keeping ${simple-java-mail.version}
at 6.7.x or earlier. (This is an inference. It is not clear from your question what version you are actually using.)
If you are going to use jakarta.mail
2.0 and later, you need to use simple-java-mail
7.0 or later.
Alternatively, you could wind back to an earlier version of javax.mail
. (There are jakarta.mail
1.6.7 artifacts in Maven Central, but the are apparently just the corresponding javax.mail
artifacts renamed.)
Answered By - Stephen C
Answer Checked By - Gilberto Lyons (JavaFixing Admin)