IMAP connection throws TimeoutException with Aspose.Email.dll 20.5

Hi Team,

I upgraded from Aspose.Email.dll 19.1 to Aspose.Email.dll 20.5. Now a customer of us cannot connect anymore with its provider via IMAP. The customer gets the following Exception:

Could not connect to IMAP: TimeoutException: The operation ‘Connect’ terminated. Timeout ‘100000’ has been reached.
at #=zOpjyArpTkbfVsmwxMZY57xINWeDr.#=zKlidF5E=(IAsyncResult #=zQJYoVKI=)
at #=zOpjyArpTkbfVsmwxMZY57xINWeDr.#=zAcr6BHc=()
at #=z6HQ9TNN2Gg4oqFtmIIi6lrTRxGT0.#=z1vcIXTa$wkC8(Int32 #=zuALJey8=, #=zKqoKWMxQNlrvqVZz2iMd519CUF1yjocakA== #=zsBWu8i4=)
at #=zOpjyArpTkbfVsmwxMZY57xINWeDr.#=zGJz9fitSEPc7()
at #=zOpjyArpTkbfVsmwxMZY57xINWeDr.#=zwIemAnA=(AsyncCallback #=zQM1JCBY=, Object #=zk$0tCEQ=)
at Aspose.Email.Clients.Imap.ImapClient.BeginGetFolderInfo(IConnection connection, String folderName, AsyncCallback callback, Object state)
at Aspose.Email.Clients.Imap.ImapClient.GetFolderInfo(String folderName)
at Com.Kendox.MailArchiver.Library.MailProviders.Imap.ImapMailProvider.Connect(MergedProfile profile, Boolean enableTrace, Action`2 callback)

Connection security: Auto selection mode

Code to connect to IMAP:

> public void Connect(MergedProfile profile, bool enableTrace, Action<bool, Exception> callback)
> {
> 		try
> 		{
> 				this.LogWriterPrefix = profile.MailBoxAddress;
> 
> 				LogWriter.WriteMessage("Trying to connect to IMAP with HostName [" + profile.ImapHostName + "], MailBoxAddress [" + profile.MailBoxAddress + "], PortNumber [" + profile.ImapPortNumber + "], SecurityOption [" + profile.ImapSecurityOption + "]", this.LogWriterPrefix, LogLevels.Info, "", Constants.EventLogType.Connect);
> 				
> 				client = new ImapClient();
> 				
> 				client.Host = profile.ImapHostName;
> 				client.Username = profile.MailBoxAddress;
> 
> 				string password = Encryption.ToInsecureString(profile.ImapMailBoxPassword);
> 				if (string.IsNullOrEmpty(password))
> 				{
> 						throw new ImapConnectionException("IMAP mailbox password is not set.");
> 				}
> 				client.Password = password;
> 
> 				client.Port = profile.ImapPortNumber;
> 
> 				// Security option
> 				if (profile.ImapSecurityOption == ImapSettings.ImapSecurityOptions.Auto)
> 				{
> 						client.SecurityOptions = SecurityOptions.Auto;
> 				}
> 				else if (profile.ImapSecurityOption == ImapSettings.ImapSecurityOptions.SSLExplicit)
> 				{
> 						client.SecurityOptions = SecurityOptions.SSLExplicit;
> 				}
> 				else if (profile.ImapSecurityOption == ImapSettings.ImapSecurityOptions.SSLImplicit)
> 				{
> 						client.SecurityOptions = SecurityOptions.SSLImplicit;
> 				}
> 				else if (profile.ImapSecurityOption == ImapSettings.ImapSecurityOptions.None)
> 				{
> 						client.SecurityOptions = SecurityOptions.None;
> 				}
> 
> 				// Tests connection to IMAP server by getting folder info of the inbox.
> 				ImapFolderInfo folderInfo = client.GetFolderInfo(ImapFolderInfo.InBox);
> 
> 				ConnectionState connectionState = client.ConnectionState;
> 				if (connectionState == ConnectionState.Open)
> 				{
> 						callback(true, null);
> 				}
> 				else
> 				{
> 						// TODO: Test, if connection status is not open.
> 						throw new ImapConnectionException("IMAP connection is closed or broken.");
> 				}
> 		}
> 		catch (Exception ex)
> 		{
> 				try
> 				{
> 						if (client != null)
> 								client.Dispose();
> 				}
> 				catch (Exception) { }
> 				if (client != null)
> 						client = null;
> 				callback(false, ex);
> 		}
> }

The above code works with Aspose.Email.fll Version 19.1, with Aspose.Email.dll Version 20.5 Aspose throws a TimeOutException. What could be the cause of the exception? Do I have to adapt the code?

P.S.: I upgraded Aspose.Email.dll to Version 20.5 in order to support TLS1.1, TLS1.2, TLS1.3.

@pfa,

Can you please try setting TimeOut value to -1 and see if that works for you. If that still fail then we request you to please provide test account credentials that we may use on our end to reproduce and resolve the issue.

I set TimeOut to -1.

Results:

  1. If I use as Connection Security “Auto selection mode” the connection to IMAP works.
  2. If I use as Connection Security “Connection is not secure” the IMAP connection hangs. After 15 minutes of waiting, I shut down the application

You could reproduce the problem by using a mail account at gmx.de.

Settings:
Host name: imap.gmx.net
Port number: 993
Connection security: Connection is not secure

Or do I have to use another port, if I use “Connection is not secure”

@pfa,

Can you please share test account credentials that we use to verify the same on our end. We tried to register using different browsers and unable to register there.

image.png (18.2 KB)

Hi,

  1. Test account credentials at gmx.de:

TestImap1.pdf (191.6 KB)

  1. Our customer who has the IMAP connection problem sent us some information:

He uses Lotus Domino 9.01 FP10 HF265.
The IMAP settings are as follows:

Customer IMAP Settings.pdf (198.5 KB)

These settings worked with Aspose.Email.dll 19.1, but not with 20.5. Maybe you can tell me why not?

@pfa,

I have created an issue with ID EMAILNET-39884 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Hi,

have you investigated our problem? Did you find a solution?

@pfa,

Actually, the valid port number for non-secured connections is port:143. You have used port: 993 for both secured and non-secured connections. That’s the reason of your problem. Please try using following sample code.

using (ImapClient client = new ImapClient())
            {
                client.Timeout = -1;
                client.Host = "imap.gmx.net";
                client.Username = "   ";
                client.Password = "     ";
                client.SecurityOptions = securityOptions;
                switch (securityOptions)
                {
                    case SecurityOptions.None:
                        {
                            client.Port = 143;
                            Assert.Throws(typeof(AsposeException), delegate()
                            {   // * CAPABILITY STARTTLS LOGINDISABLED
                                ImapFolderInfo folderInfo = client.GetFolderInfo(ImapFolderInfo.InBox);
                            });
                        }
                        break;
                    default:
                        {
                            client.Port = 993;
                            ImapFolderInfo folderInfo = client.GetFolderInfo(ImapFolderInfo.InBox);
                        }
                        break;
                }
            } 

Hi

  1. I made the test with the non-secured connection and port 143 and got the following Aspose exception:

AE_1_1_0001 BAD expected end of data instead of “%Ta87_&5l”
—> AsposeException: AE_1_1_0001 BAD expected end of data instead of “%Ta87_&5l”
—> AsposeException: AE_1_1_0001 BAD expected end of data instead of “%Ta87_&5l”
—> ImapException: AE_1_1_0001 BAD expected end of data instead of “%Ta87_&5l”
at #=z7T0xpLhuzLWoQxFFLFAiPzZcn4$0l9ZGTbaWgf4=.#=z6zXK2mestUHh(ImapStatusCode #=zEo3f8ZrNX_N5)
at #=zZcjkCeYvIgeGygVEZmvdocskk8oNKaNRjgIJVWQ=.#=z6zXK2mestUHh()
at #=zjjWtojbLcAF8M26JLDUyX8GtjtpcixFOZyKSvNY=.#=zqpNK1i8=(Object #=z9VnlUFw=)
— End of inner exception stack trace —
at #=zCCQrHjm4_8t0gTJzxZbVlLI4PzT0.#=zm6m$OKs=(IAsyncResult #=z1lMPYe0=)
at #=zCCQrHjm4_8t0gTJzxZbVlLI4PzT0.#=zA7pbz20=()
at #=zJXWdgZoq0MXT341Gyyecm9k5J_AWMYOuHKUYx3A=.#=zAWC86LmJULIjRzngB77htvU=(String #=zkMRd$fM=, Int32 #=z_WazWhs=)
at #=zJXWdgZoq0MXT341Gyyecm9k5J_AWMYOuHKUYx3A=.#=zuPnCPiY4odjm(String #=zkMRd$fM=, Int32 #=z_WazWhs=)
— End of inner exception stack trace —
at #=zJXWdgZoq0MXT341Gyyecm9k5J_AWMYOuHKUYx3A=.#=zuPnCPiY4odjm(String #=zkMRd$fM=, Int32 #=z_WazWhs=)
at #=zJXWdgZoq0MXT341Gyyecm9k5J_AWMYOuHKUYx3A=.#=zBYAtS6E=()
at #=zRnWT52DnYFWSE_UgwrLvACT8AyiX1fogRw==.#=zDqe5LPfsLg$p()
— End of inner exception stack trace —
at #=zCCQrHjm4_8t0gTJzxZbVlLI4PzT0.#=zm6m$OKs=(IAsyncResult #=z1lMPYe0=)
at #=zCCQrHjm4_8t0gTJzxZbVlLI4PzT0.#=zA7pbz20=()
at #=zLpDCtR4lOfSpkFg4O4SNjHL9Bm9B.#=z8NnE4pt1SLsk(Int32 #=zLOTc$Uc=, #=zcMuZGXhTF0d42zBknWm1rTW6jT923syjRQ== #=zOeouHEw=)
at #=zCCQrHjm4_8t0gTJzxZbVlLI4PzT0.#=zj5IRYthcvK4D()
at #=zCCQrHjm4_8t0gTJzxZbVlLI4PzT0.#=zWL1GkYM=(AsyncCallback #=zbE3oAm0=, Object #=z9VnlUFw=)
at Aspose.Email.Clients.Imap.ImapClient.BeginGetFolderInfo(IConnection connection, String folderName, AsyncCallback callback, Object state)
at Aspose.Email.Clients.Imap.ImapClient.GetFolderInfo(String folderName)

What does this mean in plain English?

  1. In my mail from July 25th I asked you two questions? Have you investigated point 2?

@pfa,

What security option you have set to obtain the exception. If I set security option as None, I get following error.

AE_1_1_0001 NO [PRIVACYREQUIRED] An error occurred accessing your GMX e-mails: Your connection is not secure. Please activate SSL in your mail program.

You have shared following two things in 25 July query. In 1, you shared credentials and in 2, you shared environment details.

  1. I did exactly as I said, I used port 143 and “None” as security. But I used another mail account (see AsposeTests.zip (4.2 MB)
    )

AsposeTests.zip contains a c# program to connect via IMAP to an email account with the email credentials.

When I use this mail account, Aspose has problems with the password. I get the following exception:
AsposeException.PNG (25.2 KB)

Why does this error appear?

@pfa,

Yes, with your second account credentials, I am able to reproduce the issue. A ticket with ID EMAILNET-39892 has been created to further investigate and resolve the issue. We will share the feedback with you as soon as the issue will be fixed.

Hi,

did you solve the problem yet?

@pfa

I regret to share that at present the concerned issue is unresolved. We request for your patience and will share the good news with you as soon as the issue will be fixed.

@pfa

Actually, usual passwords may contain special characters for the IMAP protocol, so it is important to escape it before. The server misinterpreted ‘%’ char in the password:

AE_1_1_0001 LOGIN mafferkalimo@gmx.de ************
AE_1_1_0001 BAD expected end of data instead of “%Ta****”

We can consider placing quotes around the password:

client.Username = “mafferkalimo@gmx.de”;
client.Password = “"S%Ta****"”;

But escaping password not solve the connection issue. We need to use SecurityOptions.SSLExplicit or SecurityOptions.SSLAuto to login on port 143. In case of SecurityOptions.SSL* we don’t need to escape the password. I hope the shared information will be helpful.