Aspose.Email is not working with TLS1.2 for .NET Framework 3.5

@t1jsw,
I passed this information to our development team. I will inform you about any progress.

@t1jsw,
Our development team has not managed to reproduce the error. To investigate the issue further, we need the following:

  • The code example reproducing the error
  • Valid credentials on which the error can be reproduced

The reason for the TimeoutException could be due to the lack of greetings message from the server. This situation may happen when the wrong connection configuration provided. For example, there could be a lack of TLS 1.2 support on the server.

Thanks Andrey.

I did not change anything since my original post.

Also please note that I was able to access that account via TLS 1.2 only using Aspose.Mail in one of our other products that uses a later .NET Framework version. Therefore I do not think it is because gmail is not supporting TLS 1.2.

I think it is related specifically to .NET Framework 3.5 but I am unsure if it is a problem within Aspose or a problem with server setup. Here are the specific server configuration details.

Thanks, Julie

@t1jsw,
I passed the additional information to our development team. I will inform you about any progress.

@t1jsw,
Our development team checked the code you provided again. We tried both .NET Framework 3.5 and .NET Framework 3.5 Client Profile. We also tried to set encryption to TLS 1.2 explicitly. Unfortunately, our developers still can not reproduce the error. It would be great if you could provide additional information to help us with this.

Hi,

I am not sure what further details I can provide. What version of windows was being run? What patch level? Was TLS1.0 and 1.1 explicitly turned off, so it could not fall back to using those? Were registry settings applied? Did you try with gmail and/or hotmail? If not, which mail client?

This is our setup:

We consistently get a timeout with this scenario.

Cheers, Julie

@t1jsw,
I passed your questions to our development team. Thank you for your patience.

Hi @Andrey_Potapov,

I was just wondering if there were any further updates to this.

Thanks, Julie

@t1jsw,
I requested news on this issue from our development team again. I will let you know as soon as possible.

@t1jsw,

Our development team tried with a Gmail account.

We are investigating this case, but we have several questions:

  1. Does the error reproduce with different accounts? Have any changes been made to the settings of these accounts?
  2. Is the error reproducible only on Windows Server 2019?
  3. Did you use Aspose.Email for .NET 3.5 or .NET 3.5 ClientProfile?
  4. Is the error reproducible in a standalone minimal application without your application code?

Hi @Andrey_Potapov,

  1. I can reproduce with gmail and outlook accounts. No changes have been made to these accounts. However, as I previously noted you have to allow for “Less secure App Access” to be able to access the mailbox in the first place.

  2. As well as Windows Server 2019 I can reproduce on Windows Server 2016 (14393.4350).

  3. I am using .NET 3.5 not the ClientProfile one.

  4. I reiterate, that in ALL cases I can make the same code that fails when only TLS1.2 is enabled, work by re-enabling TLS1.1 and TLS 1.0 without changing any other settings in mailboxes etc… I was able to replicate in a standalone application that comprised of a single form and a single button. Code and error below.

However I noticed that if my visual studio project was set to .NET Framework 4.0 it would work but as soon as the standalone application was set to .NET Framework 3.5 I started to experience the error if TLS1.0 and TLS 1.1 was disabled. In both of these cases I was using the same Aspose.Mail.dll (being the 3.5 one).

Our application is .NET Framework 3.5 so we need the TLS1.2 stuff to work when the application is compiled as such.

Thanks, Julie

 Private Sub btnMain_Click(sender As Object, e As EventArgs) Handles btnMain.Click
    Try

        Dim loEmailLicence As New Global.Aspose.Email.License()
        loEmailLicence.SetLicense("XXXX\Aspose.Total.lic")

        Try
            Dim loClient As New Aspose.Email.Clients.Imap.ImapClient("imap.gmail.com", 993, "XXX@gmail.com", "XXX")
            loClient.SecurityOptions = Aspose.Email.Clients.SecurityOptions.Auto
            loClient.Timeout = 30000
            loClient.SelectFolder(Aspose.Email.Clients.Imap.ImapFolderInfo.InBox)

            Dim loMsgs As Aspose.Email.Clients.Imap.ImapMessageInfoCollection = Nothing
            Dim loMsgsResult As System.IAsyncResult
            loMsgsResult = loClient.BeginListMessages(Nothing, Me)

            Do While Not loMsgsResult.IsCompleted
                'one small sleep for cpu...
                Threading.Thread.Sleep(50)
            Loop
            loMsgs = loClient.EndListMessages(loMsgsResult)

            MsgBox("Messages: " & loMsgs.Count)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    Catch ex As Exception
        MsgBox("Licence Failure!!! " & ex.ToString)
    End Try

End Sub

image.png (13.4 KB)

@t1jsw,
Thank you for the additional information. I passed it to our development team. I will inform you of any progress.

Hi @Andrey_Potapov,
Any progression with this issue?
Thanks, Julie

@t1jsw,
As I can see, the issue has been resolved. A fix will be included in Aspose.Email 21.6.

@t1jsw,
.NET Framework 3.5 did not originally support TLS 1.2. This feature was later added, but Aspose.Email checks for it by code. By code, the .NET Framework 3.5 still lacks support for TLS 1.2.

A new method will be added in Aspose.Email 21.6:

EmailClient.SetSupportedEncryptionUnsafe(EncryptionProtocols value)

This method is not safe and sets the encryption protocols without any compatibility checks.

For example, EncryptionProtocols.Tls12 considered as not supported for .NET Framework 3.5. So when you calls the code

someClient.SupportedEncryption = EncryptionProtocols.Tls | EncryptionProtocols.Tls12

only EncryptionProtocols.Tls will be used. But with Aspose.Email 21.6, you will be able to call

someClient.SetSupportedEncryptionUnsafe(EncryptionProtocols.Tls12)

and TLS 1.2 will be used even with .NET Framework 3.5.

@Andrey_Potapov thank you so much this is now working.

I just wanted to get clarification on what the SetSuportedEncryptionUnsafe method will do. Will it affect SupportedEncryption?

If Supported encryption is currently TLS or TLS11, and then I add an this additional line setting TLS12 as Unsafe are the TLS11 and TLS still enabled/supported?

Thanks, Julie

@t1jsw,
I requested this information for you from our development team. I will answer you as soon as possible.

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

@t1jsw,
If you want to set TLS, TLS 1.1 and TLS 1.2, you should use the code below:

someClient.SetSupportedEncryptionUnsafe(EncryptionProtocols.Tls | EncryptionProtocols.Tls11 | EncryptionProtocols.Tls12);

Method SetSupportedEncryptionUnsafe does not add more encryption protocols to the SupportedEncryption field. It sets all protocols from its argument and unsets the others.

Thanks @Andrey_Potapov, you response is very much appreciated :slight_smile: