无法连接到 TLS 1.2 安全邮箱服务器

发布于 2025-01-13 12:01:26 字数 1146 浏览 0 评论 0原文

我有一个简单的 C# 代码,尝试使用 Limilabs 电子邮件库访问 tls 安全邮箱服务器。

但我收到有关 Tls 1.2 的错误:

Authenticate as SSL/TLS client failed.
You might be connecting to non SSL/TLS port -or- using incorrect SSL/TLS version.
Consider using TLS 1.2: client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
Please examine the inner exception for details.

然而,在尝试访问安全邮箱服务器之前,我在代码中使用了 Tls 1.2:

 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault | SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;

而且我已在 Windows 10 注册表中添加了这些密钥:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client\Enabled = 0x00000001
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client\DisabledByDefault = 0x00000000
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto = 0x00000001
 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto = 0x00000001

您有想法吗?

预先非常感谢。

埃里克.

I have a simple C# code that tries to access to a tls secured mail box server using Limilabs email library.

But I get an error about Tls 1.2 :

Authenticate as SSL/TLS client failed.
You might be connecting to non SSL/TLS port -or- using incorrect SSL/TLS version.
Consider using TLS 1.2: client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
Please examine the inner exception for details.

Yet I use Tls 1.2 in my code before trying to access the secured mail box server :

 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault | SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;

And I have added those keys in my Windows 10 registry :

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client\Enabled = 0x00000001
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client\DisabledByDefault = 0x00000000
 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto = 0x00000001
 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto = 0x00000001

Do you have an idea ?

Thanks a lot in advance.

Eric.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

将军与妓 2025-01-20 12:01:26

Mail.dll 不使用 ServicePointManager 选择 SSL/TLS 协议版本。

要强制使用特定协议,请使用客户端的 SSLConfiguration 属性:

client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12

对于 IMAP,您的代码应如下所示:

using (Imap client = new Imap())
{
    // client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
    client.ConnectSSL("outlook.office365.com");
    client.LoginOAUTH2(userName, accessToken);

    client.SelectInbox();

    List<long> uids = client.GetAll();

    client.Close();
}

对于 SMTP(Office365 需要显式 TLS/SSL - 连接后的 StartTLS 方法):

using (Smtp client = new Smtp())
{
    // client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
    client.Connect("outlook.office365.com");
    client.StartTLS();

    client.LoginOAUTH2(userName, accessToken);

    // ...

    client.Close();
}

Mail.dll doesn't use ServicePointManager to select SSL/TLS protocol versions.

To force specific protocol use client's SSLConfiguration property:

client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12

For IMAP your code should look like this:

using (Imap client = new Imap())
{
    // client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
    client.ConnectSSL("outlook.office365.com");
    client.LoginOAUTH2(userName, accessToken);

    client.SelectInbox();

    List<long> uids = client.GetAll();

    client.Close();
}

For SMTP (Office365 requires explicit TLS/SSL - StartTLS method after Connect):

using (Smtp client = new Smtp())
{
    // client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
    client.Connect("outlook.office365.com");
    client.StartTLS();

    client.LoginOAUTH2(userName, accessToken);

    // ...

    client.Close();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文