0

I am trying to connect to MS Exchange Server using Spring Integration, but cannot find the correct configuration example to do this.

I have played with the Spring Integration github repo, and I have successfully been able to create applications that read and send emails from my gmail account using Spring Integration. I am now trying to do the same with my hotmail account, and this is where I have problems.

I have searched extensively online and found EWS configuration for connecting to Exchange Servers, I have successfully replicated my application and it is working with EWS.

However, what I really want to do is use Spring Integration in my application for reading my hotmail email messages. I found this page: Connect to Microsoft Exchange Server with Spring Integration Mail but I was unable to get a working connection after trying the configurations specified on the page out.

Can anyone help with the correct store-uri of the channel adapter? I believe that I may have the wrong for hotmail. I am using: outlook.office365.com as my url and this keeps failing.

I used this configuration:

<int-mail:imap-idle-channel-adapter id="customAdapter"
            store-uri="imaps://MYHOTMAILEMAILID:MYPASSWORD@outlook.office365.com/ews/exchange.asmx/inbox"
            channel="receiveChannel"
            auto-startup="true"
            should-delete-messages="false"
            should-mark-messages-as-read="false"
            java-mail-properties="javaMailProperties"/>

I also tried a lot of variations based on suggestions I found online but none of the configurations has worked.

11:47:30.573 WARN  [task-scheduler-1][org.springframework.integration.mail.ImapIdleChannelAdapter] error occurred in idle task
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732) ~[javax.mail-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:366) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:246) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:195) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at org.springframework.integration.mail.AbstractMailReceiver.connectStoreIfNecessary(AbstractMailReceiver.java:332) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:339) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:170) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:289) [spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:254) [spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_192]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_192]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_192]
11:47:30.582 WARN  [task-scheduler-1][org.springframework.integration.mail.ImapIdleChannelAdapter] Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.
java.lang.IllegalStateException: Failure in 'idle' task. Will resubmit.
    at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:305) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:254) [spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_192]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_192]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_192]
Caused by: javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732) ~[javax.mail-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:366) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:246) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:195) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at org.springframework.integration.mail.AbstractMailReceiver.connectStoreIfNecessary(AbstractMailReceiver.java:332) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:339) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:170) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:289) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    ... 10 more
11:47:41.717 WARN  [task-scheduler-1][org.springframework.integration.mail.ImapIdleChannelAdapter] error occurred in idle task
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732) ~[javax.mail-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:366) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:246) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:195) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at org.springframework.integration.mail.AbstractMailReceiver.connectStoreIfNecessary(AbstractMailReceiver.java:332) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:339) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:170) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:289) [spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:254) [spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_192]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_192]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_192]
11:47:41.718 WARN  [task-scheduler-1][org.springframework.integration.mail.ImapIdleChannelAdapter] Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.
java.lang.IllegalStateException: Failure in 'idle' task. Will resubmit.
    at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:305) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:254) [spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.0.M2.jar:5.2.0.M2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_192]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_192]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_192]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_192]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_192]
Caused by: javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732) ~[javax.mail-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:366) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:246) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at javax.mail.Service.connect(Service.java:195) ~[javax.mail-api-1.6.2.jar:1.6.2]
    at org.springframework.integration.mail.AbstractMailReceiver.connectStoreIfNecessary(AbstractMailReceiver.java:332) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:339) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:170) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:289) ~[spring-integration-mail-5.2.0.M2.jar:5.2.0.M2]
    ... 10 more
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Derin
  • 60
  • 1
  • 1
  • 9
  • I don't have answer for you, but take a look here, please: https://stackoverflow.com/questions/36483341/imap-access-to-mail-office-365-with-javamail. You might need those properties in the `javaMailProperties`. Also I think your URL is wrong. I believe that `ews/exchange.asmx` part must not be there, because `asmx` is for HTTP, definitely not for IMAPS. Also cosider to have `inbox` in upper case. See that SO question. – Artem Bilan Jul 14 '19 at 17:05
  • Hi Artem, Thank you for pointing out the post. I was able to connect to my hotmail account using java mail API. Appreciate your help. – Derin Jul 14 '19 at 23:46

0 Answers0