1
0
-1

Hello,

I am trying to create a plugin that would take an email and a certain text, and would send amessage to that specific email. The plugin includes other code and connection to other servers. I want this plug in to run irrespective to the application it is in and hence irrespective to any default parameters set for an email tool used. So, I cant use the email tool.I have checked the email tool code and the UserNotificationAuditTrail code to see how an email is sent in joget, and used the same way to send an email from the plugin however I am running into a ClassNotFoundException whenever trying to use the HtmlEmail and EmailException classes by org.apache.commons which both are used by the email tool and UserNotificationAuditTrail plugin.

Any help would be appreciated as to how I can achieve the required plugin.

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      I think it's because the OSGI confuse about the classpath of your library, because you are using the same library that being used in Joget Core( Email Tool)

      Try to encapsulate your functions with this

      ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
      try {

      // your code

      } finally {
      Thread.currentThread().setContextClassLoader(originalClassLoader);
      }

      1. MK

        Thank You for your reply I did as you suggested but got a LinkageError on the HtmlEmail class at runtime. This is how I used the code you added, the error I got, and the pom.xml file of the plugin. Code.txt: ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); try { final String smtpHost = "smtp.gmail.com"; String smtpPort = "465"; String smtpUsername = "xx"; String smtpPassword = "xx"; String security = "SSL"; String from = "xx"; String emailMessage = "xx \n"; //create the email message HtmlEmail email = null; try { email = AppUtil.createEmail(smtpHost, smtpPort, security, smtpUsername, smtpPassword, from); } catch (EmailException e) { e.printStackTrace(); } try { email.addTo("xx"); } catch (EmailException e) { e.printStackTrace(); } if (email == null) { } else { email.setSubject(subject); try { email.setMsg(emailMessage); } catch (EmailException e) { e.printStackTrace(); } email.setCharset("UTF-8"); try { email.send(); } catch (EmailException e) { e.printStackTrace(); } } } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } Pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">; <modelVersion>4.0.0</modelVersion> <groupId>org.joget</groupId> <artifactId>SmartPhonePushNotification</artifactId> <packaging>bundle</packaging> <version>6.0.0</version> <name>SmartPhonePushNotification</name> <url>http://www.joget.org</url>; <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.3</version> <configuration> <skipTests>false</skipTests> </configuration> <executions> <execution> <id>integration-test</id> <phase>integration-test</phase> <goals> <goal>test</goal> </goals> <configuration> <skipTests>false</skipTests> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <!-- Change package and plugin class here --> <Export-Package>org.joget</Export-Package> <Private-Package>org.joget.*</Private-Package> <Bundle-Activator>org.joget.Activator</Bundle-Activator> <Import-Package>!*,org.joget.report.dao,org.joget.report.model,org.joget.report.service,org.joget.commons.util,org.joget.plugin.base,org.joget.plugin.property.model,org.joget.plugin.property.service,org.joget.directory.model,org.joget.directory.model.service,org.joget.directory.dao,org.joget.workflow.model,org.joget.workflow.model.dao,org.joget.workflow.model.service,org.joget.workflow.util,org.joget.apps.app.dao,org.joget.apps.app.lib,org.joget.apps.app.model,org.joget.apps.app.service,org.joget.apps.datalist.lib,org.joget.apps.datalist.model,org.joget.apps.datalist.service,org.joget.apps.form.lib,org.joget.apps.form.dao,org.joget.apps.form.model,org.joget.apps.form.service,org.joget.apps.list.service,org.joget.apps.userview.lib,org.joget.apps.userview.model,org.joget.apps.userview.service,org.joget.apps.workflow.lib,javax.servlet,javax.servlet.http,org.osgi.framework;version="1.3.0"</Import-Package> <!-- End change package and plugin class here --> <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency> <Embed-Transitive>true</Embed-Transitive> <Embed-Directory>dependency</Embed-Directory> <Embed-StripGroup>true</Embed-StripGroup> <DynamicImport-Package>*</DynamicImport-Package> </instructions> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.4</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6.SEC03</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>2.5.6.SEC03</version> <scope>test</scope> </dependency> <dependency> <groupId>org.joget</groupId> <artifactId>wflow-core</artifactId> <version>6.0-SNAPSHOT</version> <scope>provided</scope> </dependency> <!-- Change plugin specific dependencies here --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>3.10.0</version> </dependency> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> <!--<dependency>--> <!--<groupId>org.apache.httpcomponents</groupId>--> <!--<artifactId>httpclient</artifactId>--> <!--<version>4.5.5</version>--> <!--</dependency>--> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-email</artifactId> <version>1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.mail/mail --> <!--<dependency>--> <!--<groupId>javax.mail</groupId>--> <!--<artifactId>mail</artifactId>--> <!--<version>1.5.0-b01</version>--> <!--</dependency>--> <!-- End change plugin specific dependencies here --> </dependencies> <distributionManagement> <repository> <id>internal</id> <url>http://dev.joget.org/archiva/repository/internal</url>; </repository> <snapshotRepository> <id>snapshots</id> <url>http://dev.joget.org/archiva/repository/snapshots</url>; </snapshotRepository> </distributionManagement> </project> The error file wss too big to copy. Is it okay if i share via google drive or so? Any help would be much appreciated. Thannk you for your time

      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi, I think for linkage error, you may need to create your HtmlEmail by your own code instead of using AppUtil.createEmail(smtpHost, smtpPort, security, smtpUsername, smtpPassword, from); .

        CommentAdd your comment...