SpringIntegration Mail Failed to create new store connection Unrecognised SSL message

北城余情 提交于 2019-12-25 06:38:58

问题


I have a strange exception that happens since a week in a production environment, sporadically. Everything worked fine until now.

In the code I am connecting using imap to an MS Exchange server to read the emails. This part of the code is still working ok.

Once the email has been read it is archived in a subfolder. This is this part that is sometimes sending exception.

The exception is "Failed to create new store connection".

And just after this message I always have the following exception in the traces:

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:117)
    at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:144)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:192)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:55)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:149)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:146)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:298)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:292)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.mail.MessagingException: Unrecognized SSL message, plaintext connection?;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:726)
    at javax.mail.Service.connect(Service.java:364)
    at javax.mail.Service.connect(Service.java:245)
    at javax.mail.Service.connect(Service.java:194)
    at org.springframework.integration.mail.AbstractMailReceiver.connectStoreIfNecessary(AbstractMailReceiver.java:227)
    at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:238)
    at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:260)
    at org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:103)

What I think strange is that it is only when I connect to the store that this happens. I can still read the emails with no problems.

The exception is thrown in this piece of code:

public void saveMessage(MimeMessage message, String folderName) {
    try {
        Folder folder = message.getFolder();
        folder.open(Folder.READ_WRITE);
        // Mark the message as Delete in its folder
        String messageId = message.getMessageID();
        Message[] messages = folder.getMessages();

It seems it is the getFolder that sends the message.

What I can't figure out is why do I have an SSL exception when I try to get access to the store, while the same uri is used without any issue to read the emails.

I have the following configuration:

<int:channel id="receiveChannel" datatype="javax.mail.internet.MimeMessage"/>

<int-mail:inbound-channel-adapter id="incomingEmailsAdapter"
    store-uri="${inboundMail.storeUri}"
    channel="receiveChannel"
    should-delete-messages="false"
    should-mark-messages-as-read="true"
    auto-startup="${inboundMail.startup}"
    java-mail-properties="javaMailInboundProperties">
    <int:poller max-messages-per-poll="${inboundMail.nb.poll}" fixed-rate="${inboundMail.nb.rate}"/>
</int-mail:inbound-channel-adapter>

<util:properties id="javaMailInboundProperties">
    <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
    <prop key="mail.imaps.ssl.trust">*</prop>
    <prop key="mail.imap.socketFactory.fallback">false</prop>
    <prop key="mail.store.protocol">imaps</prop>
    <prop key="mail.debug">${inboundMail.debug}</prop>
</util:properties>

<int:service-activator id="serviceActivator" input-channel="receiveChannel" ref="mailService" method="handleMail"/>

with:

inboundMail.storeUri = imaps://Unknown:REDACTED@company.com:993/inbox

Why can I read emails with this uri, and can I not open the store with the same one?

This issue happens several times a day, since a week.

Any idea where it could come from?

Thanks

Gilles

来源:https://stackoverflow.com/questions/37503821/springintegration-mail-failed-to-create-new-store-connection-unrecognised-ssl-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!