Skip to main content



      Home
Home » Eclipse Projects » GlassFish » Application deployed on glassfish 6 fail to send email(Email from the application is not working from glassfsih 6.0.0 due to conflict of javax mail libraries )
Application deployed on glassfish 6 fail to send email [message #1849674] Fri, 28 January 2022 17:05
Eclipse UserFriend
Email from the application is not working from glassfish 6.0.0 due to conflict of javax mail library with the glassfish 6 mail libraries from a modules folder.
We have REST application implemented using jersey 3.0.0 deployed on glassfish 6. We are using log4j for logging. When there is an error, it failed to send the email. I tried the same application from localhost using tomcat it is sending an email.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<!-- <exclusions> <exclusion>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
</exclusion>
</exclusions> -->
</dependency>

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.6.5</version>
<exclusions>
<exclusion>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
</exclusion>
</exclusions>
</dependency>

<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<properties>
<!-- <jersey.version>3.0.0-M1</jersey.version> -->
<jersey.version>3.0.0</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

I also tried replacing log4J 1.x to log4j2
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
With Jakarta.mail.jar I am receiving below error
java.lang.ClassCastException: com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler

I tried replacing Jakarta.mail.jar with javax.mail.jar
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>

I received the below error
ERROR An exception occurred processing Appender LogToMail org.apache.logging.log4j.core.appender.AppenderLoggingException: java.lang.NoSuchMethodError: com.sun.mail.util.MimeUtil.cleanContentType

Tried with mail.jar instead of javax.mail.jar
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
Getting below Error
java.lang.NoSuchMethodError: com.sun.mail.util.PropUtil.getBooleanSessionProperty

As there is already some other mail library there in classloader I removed the mail library from the application then I am getting
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
I tried copying jakarata.mail and jakarata.activation.jar under glassfish/domains/domain1/lib/ext folder but getting NOSTMP provider. If I copy javax.mail.jar and activation.jar under glassfish/domains/domain1/lib/ext folder then same error "ERROR An exception occurred processing Appender LogToMail org.apache.logging.log4j.core.appender.AppenderLoggingException: java.lang.NoSuchMethodError: com.sun.mail.util.MimeUtil.cleanContentType"

I also tried adding mail.jar and activation.jar under glassfish/domains/domain1/lib/ext folder
ERROR Caught exception while sending e-mail notification.: javax.mail.NoSuchProviderException: smtp javax.mail.NoSuchProviderException: smtp

I referred to StackOverflow for the below solution. Not completely understood what xbootclasspath does but tried adding the below lines to domain.xml.

<jvm-options>-Xbootclasspath/p:${com.sun.aas.installRoot}/modules/jakarta.mail.jar </jvm-options>
<jvm-options>-Xbootclasspath/p:${com.sun.aas.installRoot}/modules/jakarta.activation.jar </jvm-options>

Appreciate your help on this.
Previous Topic:Glassfish & broker
Next Topic:Glassfish 6.2.2 CDI deployment failure:null
Goto Forum:
  


Current Time: Wed Apr 30 20:15:34 EDT 2025

Powered by FUDForum. Page generated in 0.05687 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top