【问题标题】:Getting an error when trying to connect to SMTP server "199.201.221.19"尝试连接到 SMTP 服务器“199.201.221.19”时出错
【发布时间】:2023-03-03 08:22:24
【问题描述】:

我正在使用以下代码,但在尝试连接到 SMTP 服务器时出现错误。我没有提供任何身份验证凭据来访问它。

var client = new SmtpClient()
await client.ConnectAsync("199.201.221.19", 587, false);
client.Send(mail);

主机:199.201.221.19 端口:587 错误:System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效。 实际问题是什么?对此可能的解决方案是什么?

【问题讨论】:

    标签: c# email smtp smtpclient mailkit


    【解决方案1】:

    该错误是指 SSL/TLS 证书验证错误。这意味着您的服务器的 SSL 证书没有使用 .NET 的标准根 CA 证书进行验证。

    即使您在 ConnectAsync() 方法调用中将 useSsl 指定为 false,如果服务器支持 STARTTLS,MailKit 仍将切换到 TLS 模式。 useSsl 参数实际上仅用于告诉 MailKit 端口是否从一开始就需要 SSL(如 ssl 包装的端口,例如 IMAP/S 的 993、POP/S 的 995 和 SMTP/S 的 465) .

    您有 2 个选项来解决此问题:

    1. 按照常见问题解答中有关此错误的说明进行操作:https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate
    2. 使用不同的 ConnectAsync 方法,允许您指定不尝试 STARTTLS:client.ConnectAsync (host, port, SecureSocketOptions.None);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-29
      • 2016-12-03
      • 2020-01-07
      • 2020-10-14
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 2018-10-07
      相关资源
      最近更新 更多