Hi,
We are using aspose-email-17.3.0-jdk16.jar since long time. We got a new error never happened before:
On ImapClient.SelectFolder(ImapFolderInfo.IN_BOX) we have a timeout exception (Connection failure. Timeout ‘200000’ has been reached).
The program runs every 15 minutes. Can you please help.
Here is my code:
@elie.kach,
Thank you for contacting support. Unfortunately, I was unable to reproduce the exception on my side. Please try to set the timeout before calling the selectFolder method as shown below:
I put setTiemout before selectFolder but timeout no effect because in the exception we still see 200000.
I will try again again with latest version.
Please note that this issue is random, it occurs time to time, even if no messages in the inbox
email host: pod51009.outlook.com
OS version: Windows 10 professional and Windows server 2012 R2
I was able to user version 18.9 and I confirm that setting timeout (900000) before SelectFolder has no effect (Connection failure. Timeout ‘200000’ has been reached)
I cannot use last version (21.9) because of my licence, is it possible to get a temporary licence for one or two weeks to perform more tests?
I noticed that you use very old outlook settings. All Office 365 accounts email accounts have been upgraded. Recommended changes from MS:
IMAP connections:
Need to change pod51009.outlook.com to outlook.office365.com for incoming server
Need to change pod51009.outlook.com to smtp-mail.office365.com for outgoing SMTP server
Could you please try outlook.office365.com instead of pod51009.outlook.com. I checked both servers and they both work in my case, but the second one is much much slower. Maybe that’s the reason.
@elie.kach I have registered the EMAILJAVA-34960 task in the Aspose.Email for Java tracker for further investigation. Our dev team will try to reproduce the problem and find a solution. You will be notified when the issue is resolved.
Could you please add System.setProperty("javax.net.debug","all"); call before client.selectFolder(ImapFolderInfo.IN_BOX); and send us all logs from the console.
And please clarify: is the “Unable to connect to the server” error persistent when using v21.9 or it is a random one and occurs from time to time?
More info: Aspose java email is running within a frame and not as a standalone java application. So from within this framwork I dont see traces but as a standalone application I can see more traces.
I run the program as a standalone java application on the same server where the issue appears. I got traces and see the error.
I think issue is related to that machine because don’t occur on another machine.java-debug.zip (3.6 KB)debug.net.zip (7.8 KB)
I add a second log file which I think more consistent.logs.zip (7.7 KB)
Perhaps there is a missing certificate in the Java keystore on the machine. You can try the following code to temporary disable certificates validation and check:
import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public static SSLSocketFactory getSSLSocketFactory() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
try {
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
return sslContext.getSocketFactory();
} catch (java.lang.Exception e) {
throw new RuntimeException(e);
}
}
public final void test()
{
System.setProperty("javax.net.debug","all");
EmailClient.setSocketsLayerVersion2SSLSocketFactory(getSSLSocketFactory());
// existing code
client = new ImapClient();
client.setHost(emailHost);
client.setPort(Integer.parseInt(emailPort));
client.setUsername(user);
client.setPassword(password);
// ...
}
Thanks, It works. Is there any security issue if we use this workaround?
Can you tell me what kind of certificate is missing in order to add it to the keystore?
Is there any security issue if we use this workaround?
Yes, there are! And I cannot recommend skipping the certificate check for production.
Can you tell me what kind of certificate is missing in order to add it to the keystore?
Unfortunately not, you have to analyze it yourself (or use a keystore from another machine without this error).
Also, please note: the code example above explicitly sets TLSv1.2 protocol , whereas old Java versions use TLSv1 by default. You can configure the JVM for which version of TLS to use:
-Dhttps.protocols=TLSv1.2,TLSv1.1
Or do this manually for Aspose.Email connections. The code above should work, just remove the sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); call.