Getting an error while trying to read mail through IMAP in mule esb 3.9

60 Views Asked by At

We get below error, when we are trying to access our outlook mail which is hosted on Azure Cloud

    2023-10-24 20:58:30,087 [INFO] mail.test | Cron Job TokenValidityPoll Called
->-> Not provider of jakarta.mail.util.StreamProvider was found
     java.lang.IllegalStateException: Not provider of jakarta.mail.util.StreamProvider was found
            at jakarta.mail.util.FactoryFinder.find(FactoryFinder.java:61)
            at jakarta.mail.util.StreamProvider.provider(StreamProvider.java:199)
            at jakarta.mail.Session.<init>(Session.java:256)
        at jakarta.mail.Session.getInstance(Session.java:326)
        at com.test.AzureMailFetcher.imapAuthenticationAttempt(AzureMailFetcher.java:143)

Our code on line 143 is like below (line number marked inside code as comment **)

private static Store imapAuthenticationAttempt(IAuthenticationResult result) throws MessagingException {
    String accessToken = result.accessToken();
    Properties props = new Properties();
    props.put("mail.imap.sasl.enable", "true");
    props.put("mail.imap.sasl.mechanisms", "XOAUTH2");
    props.put("mail.imap.auth.login.disable", "true");
    props.put("mail.imap.auth.plain.disable", "true");
    props.put("mail.imap.ssl.enable", "true");
    Session session = Session.getInstance(props); // This is line number 143 ***
 Store store = session.getStore("imap");

The other important fact is that when we are trying to run through a normal java program we are able to make it work. But when we attached it as a mule component, then it started to fail. We are very sure it could be a because of the library incompatibility. But we are not sure, which library is causing this problem. We tried adding and removing few libraries, but yet no result.

I also tried using eclipse angus library, it resolved this problem but produce a new issue. So I reverted back

Below are dependencies in my project.

]

<dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>msal4j</artifactId>
            <version>1.13.8</version>
        </dependency>
    
    <dependency>
        <groupId>jakarta.mail</groupId>
        <artifactId>jakarta.mail-api</artifactId>
        <version>2.1.2</version>
        <exclusions>
            <exclusion>
                <artifactId>activation</artifactId>
                <groupId>jakarta.activation</groupId>
            </exclusion>
        </exclusions>           
    </dependency>
    <dependency>
       <groupId>com.sun.mail</groupId>
       <artifactId>jakarta.mail</artifactId>
       <version>2.0.1</version>
        <exclusions>
            <exclusion>
                <artifactId>activation</artifactId>
                <groupId>jakarta.activation</groupId>
            </exclusion>
        </exclusions>          
    </dependency>

We use jdk 1.8

Can any one help? Hopefully @aled any suggestions?

0

There are 0 best solutions below