Free Support Forum - aspose.com

Aspose.Email TLS connection issues over IMAP connection

I’m using Aspose Email 19.0.8 to connect to hMailServer 5.6.7-B2425 over IMAP/TLS with self signed certificate (https://www.hmailserver.com/documentation/v5.3/?page=reference_sslcertificates)

I’m able to connect to hMailServer mailbox over IMAP/TLS using Outlook but Aspose.Mail throws an exception.

System.OperationCanceledException
HResult=0x8013153B
Message=Operation has been canceled
Source=Aspose.Email
StackTrace:
at #=zHdLovjEEIod1mV72IF09M1E9Zvpw.#=zBGkfXas=(IAsyncResult #=zS9deMoU=)
at #=zHdLovjEEIod1mV72IF09M1E9Zvpw.#=zsFvFw3A=()
at #=z5f$tMCpGuWPXNsZ4baqOjm5cEK2YH2NSd_RI70U=.#=z8nYA1rQ=(#=zYRwXGXKU9cRRmCIKilOt9F_OXQBfkBaQ6w== #=zTDXZlVY=)
at #=zu$FnsJBaomaGGgGs$h2dPwP9seOK.#=zALMMRY$3NG8v(Int32 #=zioqX20U=, #=zYRwXGXKU9cRRmCIKilOt9F_OXQBfkBaQ6w== #=zJ5$sVuc=)
at #=zHdLovjEEIod1mV72IF09M1E9Zvpw.#=zr6S0mjEYND1Y()
at #=zHdLovjEEIod1mV72IF09M1E9Zvpw.#=znDtpZrs=(AsyncCallback #=z8q99aUU=, Object #=z2RXhc3k=)
at Aspose.Email.Clients.Imap.ImapClient.BeginListMessages(IConnection connection, String folderName, Int64 modificationSequence, Boolean retrieveRecursively, IEnumerable`1 messageExtraFields, AsyncCallback callback, Object state)
at Aspose.Email.Clients.Imap.ImapClient.ListMessages(String folderName)
at ConsoleApp13.Program.Main(String[] args) in …\Visual Studio 2017\Projects\ConsoleApp13\ConsoleApp13\Program.cs:line 25

Using the following code to connect

        var client = new ImapClient();
        client.Host = "127.0.0.1";
        client.Port = 993;
        client.Username = "...";
        client.Password = "...";
        client.SecurityOptions = SecurityOptions.SSLImplicit;
        client.SupportedEncryption = EncryptionProtocols.Tls12;

        var messages = client.ListMessages("Inbox");

Please advise

@PatrikM,

I have observed the information shared by you. Can you please share the credentials for the test account that is reproducing issue on your end and that we may use on our end to verify the issue. Please share the requested information so that we may proceed further to help you out.

I can’t see how that would possibly matter but fine by me.

The following code works just fine, IMAP over unencrypted connection

    static void Main(string[] args)
    {
        var client = new ImapClient();

        client.Host = "127.0.0.1";
        client.Port = 143;
        client.Username = "jira";
        client.Password = "jira123";
        var messages = client.ListMessages("Inbox");
    }

The following fails, only difference is the SSL certificate and TLS encryption on 993. Connecting using Outlook or other commercial e-mail clients works fine.

    static void Main(string[] args)
    {
        var client = new ImapClient();

        client.Host = "127.0.0.1";
        client.Port = 993;
        client.Username = "jira";
        client.Password = "jira123";
        client.SecurityOptions = SecurityOptions.SSLImplicit;
        client.SupportedEncryption = EncryptionProtocols.Tls12;

        var messages = client.ListMessages("Inbox");
    }

certificate.zip (2.5 KB)

This is the Certificate I use if that helps, it’s self signed using OpenSSL and for development purposes only so I don’t mind sharing it publicly.

@PatrikM,

Thank you for sharing the information with us. I have been able to observe the issue and a ticket with ID EMAILNET-39583 has been added in our issue tracking system to further investigate and resolve the ticket. This thread has been linked with the issue so that you may be notified once it will be addressed.

@mudassir.fayyaz,

How can we track the status of this issue you created? EMAILNET-39583

We have pending installations at customer sites that are depending on the functionality.

Thanks!

@nlundqu,

Thanks for contacting us. I like to inform that this issue is going to be resolved in Aspose.Email 19.10. I request for your patience.

Hi,

I see that Aspose.Email 19.10 is released but does not include EMAILNET-39583?

This would be disappointing… to say the least.

@nlundqu,

I like to inform that this issue will be resolved in 19.11. We will share good news with you soon.

We look forward to good news. Trust the issue will be resolved in 19.11.

Please post a message here when the issue has been resolved - so that we also can update our customers with the good news, as soon as possible.

@nlundqu,

Sure, we will notify you once issue will be resolved and 19.11 will be released.

Hi,

Would appreciate if you can please share the status of EMAILNET-39583?

Best regards,
Niclas

@nlundqu

I like to inform that this issue has been marked resolved in 19.11 and. This version of Aspose.Email will be rolled out soon for customers. I request for your patience.

The issues you have found earlier (filed as EMAILNET-39583) have been fixed in this update.

Hi @Adnan.Ahmad,
we have now tried version 19.11 with the exact same setup as originally described in this post and we still get the EXACT same error. How is it exactly you have resolved this problem?

Please re-open EMAILNET-39583

FYI @nlundqu

To verfiy my email server and TLS setup I tried using the S22.Imap client libary with the following source code and it works just fine.

using (var client = new ImapClient("127.0.0.1", 993, "...", "...", AuthMethod.Login, true))
{
    var uids = client.Search(SearchCondition.Unseen());
    var messages = client.GetMessages(uids);
    Console.WriteLine($"Found {messages.Count()} messages.");
}

If we were not already heavily invested in the Aspose.Mail client library for e-mail post processing I would not mind switching to the S22 libraries, but this would amount to a lot of development and testing resources being redirected. We would prefer if you could solve this issue as promised, twice

@PatrikM,

I have verified the issue details in our issue tracking system. We have included a new property

X509CertificateCollection EmailClient.ClientCertificates { get; }

For correct authentication you will have to add your own certificate as X509Certificate object to the mentioned collection.

Can you please try using the suggested options.

As you suggested , I tried the code but getting operation invalid error.

Can you please share sample code or confirm the below code is correct .

        ImapClient client = new ImapClient();
        client.Host = "";
        client.Port = 993;
        client.Username = "";
        client.Password = "";
        client.SecurityOptions = SecurityOptions.SSLImplicit;
        client.SupportedEncryption = EncryptionProtocols.Tls12;


        X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
        store.Open(OpenFlags.OpenExistingOnly);

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = store.Certificates[0];

        client.ClientCertificates.Add(cert); 
        client.SelectFolder(ImapFolderInfo.InBox);
        ImapMessageInfoCollection list = client.ListMessages();

Getting Operation invalid error from the last line.

@suvasu,

Can you please share the working sample project with a test account access that we try on our end to investigate further.

NO, all the code you need is included in my first post… The certificate is installed on the email server, you shouldn’t load the certificate from the client certificate store.