Search code examples
c#.netemailtls1.2

OpenPop library how to use TLS


I need to enable tls protocol on openpop library (TLS v.1.2 or TLS v.1.1 ) how to ?

I tried the following code but it did not work:

using (Pop3Client client = new Pop3Client())
{
    client.Connect("my_hostname", 25, false);
}

https://www.nuget.org/packages/OpenPop.NET


Solution

  • According the documentation available here: http://hpop.sourceforge.net/documentation/index.html

    The class Pop3client has a connect method with a "useSsl" parameter:

    public void Connect(
       string hostname,
       int port,
       bool useSsl
    );
    

    Try to connect using the right port and set this parameter as true:

    using (Pop3Client client = new Pop3Client())
    {
        client.Connect("your_hostname", 995, true);
    }
    

    This should validate the server certificate automatically, if you want to do this manually or if you are using a self-signed certificate you can create your own certificate validator:

    private static bool certificateValidator(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
    {
        return true;
    }
    
    using (Pop3Client client = new Pop3Client())
    {
        client.Connect("your_hostname", 995, true, 3000, 3000, certificateValidator);
    }
    

    More info here: http://hpop.sourceforge.net/exampleOverrideSSL.php