Not fetching emails after mail server host connection failed

0
Scheduled event runs microflow to fetch emails every 5 mins. Mail server was down for half an hour when this error appeared:ERROR:2026-03-06T23:45:43.675877 [runtime-container/6qblv] ERROR - Email_Connector: Batch fetching failed!com.mendix.datahub.connector.email.utils.EmailConnectorException: EC0x019: Error while creating session. at com.mendix.datahub.connector.email.service.ReceiveEmailStoreProvider.createStore(ReceiveEmailStoreProvider.java:41) at com.mendix.datahub.connector.email.service.ReceiveEmailHandler.<init>(ReceiveEmailHandler.java:47) at com.mendix.datahub.connector.email.service.IMailProvider.readMails(IMailProvider.java:20) at com.mendix.datahub.connector.email.service.ReceiveEmailBatchTask.run(ReceiveEmailBatchTask.java:32) at java.base/java.lang.Thread.run(Unknown Source)Caused by: org.eclipse.angus.mail.util.MailConnectException: Couldn't connect to host, port: xxx.xxx, xxx; timeout xxx at org.eclipse.angus.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732) at jakarta.mail.Service.connect(Service.java:345) at jakarta.mail.Service.connect(Service.java:225) at jakarta.mail.Service.connect(Service.java:246) at com.mendix.datahub.connector.email.service.ReceiveEmailStoreProvider.createStore(ReceiveEmailStoreProvider.java:35) at com.mendix.datahub.connector.email.service.ReceiveEmailHandler.<init>(ReceiveEmailHandler.java:47) at com.mendix.datahub.connector.email.service.IMailProvider.readMails(IMailProvider.java:20) at com.mendix.datahub.connector.email.service.ReceiveEmailBatchTask.run(ReceiveEmailBatchTask.java:32) at java.base/java.lang.Thread.run(Unknown Source)Caused by: java.net.SocketTimeoutException: Connect timed out at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source) at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source) at java.base/java.net.SocksSocketImpl.connect(Unknown Source) at java.base/java.net.Socket.connect(Unknown Source) at org.eclipse.angus.mail.util.SocketFetcher.createSocket(SocketFetcher.java:358) at org.eclipse.angus.mail.util.SocketFetcher.getSocket(SocketFetcher.java:235) at org.eclipse.angus.mail.iap.Protocol.<init>(Protocol.java:117) at org.eclipse.angus.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:132) at org.eclipse.angus.mail.imap.IMAPStore.newIMAPProtocol(IMAPStore.java:755) at org.eclipse.angus.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:690) at jakarta.mail.Service.connect(Service.java:345) at jakarta.mail.Service.connect(Service.java:225) at jakarta.mail.Service.connect(Service.java:246) at com.mendix.datahub.connector.email.service.ReceiveEmailStoreProvider.createStore(ReceiveEmailStoreProvider.java:35) at com.mendix.datahub.connector.email.service.ReceiveEmailHandler.<init>(ReceiveEmailHandler.java:47) at com.mendix.datahub.connector.email.service.IMailProvider.readMails(IMailProvider.java:20) at com.mendix.datahub.connector.email.service.ReceiveEmailBatchTask.run(ReceiveEmailBatchTask.java:32) at java.base/java.lang.Thread.run(Unknown Source)2026-03-06T23:45:43.676173 [runtime-container/6qblv] ERROR - Email_Connector: fetch failed!2026-03-06T23:45:43.676478 [runtime-container/6qblv] ERROR - Email_Connector: BatchFailedException : EC0x019: Error while creating session.Stacktrace : com.mendix.datahub.connector.email.utils.EmailConnectorException: EC0x019: Error while creating session. at com.mendix.datahub.connector.email.service.ReceiveEmailStoreProvider.createStore(ReceiveEmailStoreProvider.java:41) at com.mendix.datahub.connector.email.service.ReceiveEmailHandler.<init>(ReceiveEmailHandler.java:47) at com.mendix.datahub.connector.email.service.IMailProvider.readMails(IMailProvider.java:20) at com.mendix.datahub.connector.email.service.ReceiveEmailBatchTask.run(ReceiveEmailBatchTask.java:32) at java.base/java.lang.Thread.run(Unknown Source)Caused by: org.eclipse.angus.mail.util.MailConnectException: Couldn't connect to host, port: xxx.xxx, xxx; timeout xxx; nested exception is: java.net.SocketTimeoutException: Connect timed out at org.eclipse.angus.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732) at jakarta.mail.Service.connect(Service.java:345) at jakarta.mail.Service.connect(Service.java:225) at jakarta.mail.Service.connect(Service.java:246) at com.mendix.datahub.connector.email.service.ReceiveEmailStoreProvider.createStore(ReceiveEmailStoreProvider.java:35) ... 4 moreCaused by: java.net.SocketTimeoutException: Connect timed out at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source) at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source) at java.base/java.net.SocksSocketImpl.connect(Unknown Source) at java.base/java.net.Socket.connect(Unknown Source) at org.eclipse.angus.mail.util.SocketFetcher.createSocket(SocketFetcher.java:358) at org.eclipse.angus.mail.util.SocketFetcher.getSocket(SocketFetcher.java:235) at org.eclipse.angus.mail.iap.Protocol.<init>(Protocol.java:117) at org.eclipse.angus.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:132) at org.eclipse.angus.mail.imap.IMAPStore.newIMAPProtocol(IMAPStore.java:755) at org.eclipse.angus.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:690) ... 8 moreAfter mail server started again, logs every 5 minutes show that it fetches: INFO - Email_Connector: fetch complete!But it does not.All upcoming mails after that error are not fetched in until i RESTART the mendix app, then on first fetch all mails that got recieved showed up in mendix. Using an email connector, manual fetch also did not retrieve any mails from server it that time, just logs: INFO - Email_Connector: fetch complete!Any help is appreciated.Thank you!
asked
3 answers
2

Hi Patrik Cumurdzic


This is a known Email Connector bug: after a long IMAP downtime, the connector’s IMAP session gets stuck. It logs “fetch complete!” but never reconnects until the Mendix app restarts.

Why: Session dies on SocketTimeoutException, but the connector doesn’t recreate the IMAPStore.

Fixes / Workarounds:

  • Update to the latest Email Connector module.
  • Recreate the Email configuration object on every scheduled run.
  • Catch EmailConnectorException and force a new connector instance.
  • Worst case: periodic app restart.


answered
0

It looks like the problem started when the mail server was down and the connector failed to create a session. The key error is:


EC0x019: Error while creating session

caused by

SocketTimeoutException: Connect timed out


So when the IMAP server was unavailable, the Email Connector could not establish the connection. After the server came back, the scheduled event kept running and logging fetch complete!, but it seems the connector did not properly recover its connection state. That’s why no new emails were fetched.


The fact that everything works again after restarting the Mendix app strongly suggests that the connector was stuck in a bad state and the restart forced it to create a fresh connection/session.


A few things you could check:


First, make sure you are using the latest version of the Email Connector module, since recovery after connection failures might have been improved in newer versions.


Second, review the microflow that runs in the scheduled event. If the connection fails, it is worth handling that exception explicitly and making sure the connector/session is reinitialized instead of continuing as if the fetch succeeded.


Also, manual fetch not working during that time is a strong sign that the issue is probably not the scheduled event itself, but the connector session getting stuck after the timeout.


So my guess is that the connector did not recover cleanly after the IMAP timeout, and restarting the Mendix runtime reset that state.


If this resolve your issue, please close the topic. 


answered
0

Hi,


This is a known behavior with the Email Connector receive flow when the IMAP connection fails while the batch task is running. What is happening in your case is that when the mail server was unavailable, the connector failed while creating the IMAP store:

MailConnectException / SocketTimeoutException

After that failure the ReceiveEmailBatchTask thread remains alive but the IMAP session/store is already invalid. The scheduled event keeps triggering the receive logic every 5 minutes, but internally the connector is still holding that broken state, so it logs:

Email_Connector: fetch complete!

even though it is not actually reconnecting to the mail server.

When you restart the Mendix runtime the whole mail session and IMAP store are recreated, which is why on the first run after restart all the missing emails are fetched.

Why manual fetch also didn't work

Manual fetch calls the same ReceiveEmailHandler logic, which uses the existing store/session. Since the store was already in a failed state, it never re-established a fresh connection.

The safest way to avoid this is to force the connector to create a new session each time it runs, instead of relying on the previous handler state.

Typical implementation:

  1. Wrap the ReceiveEmail action in your own microflow.
  2. Add error handling around the receive call.
  3. When a connection error occurs, log it and let the next scheduled run recreate the connection.

Example pattern:

Scheduled Event
   → Custom MF_FetchEmails
        → Call ReceiveEmail (Email Connector)
        → Error handling = Custom

If the receive fails:

Catch exception
Log error
End microflow

This prevents the failed batch task from keeping a broken state.

Also check the following

1. Upgrade the Email Connector module

Older versions of the Email Connector had several issues around IMAP reconnects and stale sessions. Make sure you are using the latest version compatible with Mendix 10.

2. Reduce connection timeout

If your mail server occasionally becomes unavailable, configure a lower IMAP timeout so the connector fails quickly and retries in the next scheduled execution.

3. Avoid long-lived sessions

Make sure the receive logic does not keep a persistent IMAP session between runs.

The issue is not that Mendix stops fetching emails. The problem is that the Email Connector keeps a broken IMAP session after the server outage, so subsequent fetches run but do not reconnect.

Restarting the app fixes it because it forces a new IMAP session. Implementing proper error handling and ensuring a fresh session per scheduled run prevents the issue without needing to restart the runtime.


answered