+1 vote

Hello,

I would like to switch to using TLS instead of SSL for Gmail IMAP.
Due to SSL vulnerabilities customer wants us to switch to TLS. Our current implementation calls imapClient.ConnectSSL & then imapClient.Login. Is there a property that I can use to set to TLS?

Thanks!

by
retagged by

1 Answer

0 votes
 
Best answer

You can specify which protocols are used using SSLConfiguration property:

using (Imap client = new Imap())
{
    // Allow TLS only:
    client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls;

    client.ConnectSSL("imap.gmail.com");

    SslProtocols protocols = ((SslStream) client.ReadStream).SslProtocol;
    if (protocols != SslProtocols.Tls)
        throw new Exception("This is just to show that TLS is used. " +
                            "No need for such check in the real application.");

    client.UseBestLogin("pat@gmail.com", "password");

    client.Close();
}
by (301k points)
selected by
Thank you! Is it possible to specify the Tls version or it just picks the latest?
SslProtocols.Tls will use 1.0 version. You can use SslProtocols.Tls11 (for 1.1) and SslProtocols.Tls12 (for 1.2) in .NET 4.5 and above.
...