简体   繁体   English

不使用 SSL 或 TLS 时 MailKit 中的 SSL 或 TLS 连接错误

[英]SSL or TLS connection error in MailKit while NOT using SSL or TLS

I am using MailKit to send emails.我正在使用 MailKit 发送电子邮件。 I don't use SSL or TLS and using port 25. The mail server I am using has port 25 open.我不使用 SSL 或 TLS 并使用端口 25。我使用的邮件服务器打开了端口 25。 What is hapening is that most of the times emails are sent without any problems and sometimes I get the following exception令人高兴的是,大多数时候电子邮件都没有任何问题发送,有时我会收到以下异常


An error occurred while attempting to establish an SSL or TLS connection.尝试建立 SSL 或 TLS 连接时出错。

The SSL certificate presented by the server is not trusted by the system for one or more of the following reasons:服务器出具的SSL证书不被系统信任,有以下一种或多种原因:

  1. The server is using a self-signed certificate which cannot be verified.服务器正在使用无法验证的自签名证书。
  2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.本地系统缺少验证服务器证书所需的根证书或中间证书。
  3. The certificate presented by the server is expired or invalid.服务器提供的证书已过期或无效。

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate for possible solutions.有关可能的解决方案,请参阅https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection. MailKit.Security.SslHandshakeException:尝试建立 SSL 或 TLS 连接时发生错误。

The SSL certificate presented by the server is not trusted by the system for one or more of the following reasons:服务器出具的SSL证书不被系统信任,有以下一种或多种原因:

  1. The server is using a self-signed certificate which cannot be verified.服务器正在使用无法验证的自签名证书。
  2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.本地系统缺少验证服务器证书所需的根证书或中间证书。
  3. The certificate presented by the server is expired or invalid.服务器提供的证书已过期或无效。

Here is the code sample I use这是我使用的代码示例

在此处输入图像描述


My questions are: 1 - why it tries to use SSL or TLS given that I set not to use it 2 - why it happens randomly我的问题是: 1 - 为什么它尝试使用 SSL 或 TLS,因为我设置不使用它 2 - 为什么它随机发生

The ConnectAsync() method that takes a bool useSsl argument only specifies whether the initial connection must use SSL (or, as another way of wording it, it specifies whether the port you are connecting to is SSL-wrapped).采用bool useSsl参数的 ConnectAsync() 方法仅指定初始连接是否必须使用 SSL(或者,作为另一种措辞,它指定您连接的端口是否是 SSL 包装的)。

As an example of an SSL-wrapped port, for SMTP that would be port 465.作为 SSL 包装端口的示例,对于 SMTP,端口 465。

This option does not tell MailKit whether or not to use the STARTTLS command once the plain-text connection is established.一旦建立了纯文本连接,此选项不会告诉 MailKit 是否使用 STARTTLS 命令。

If you want to disable SSL/TLS completely, use the ConnectAsync() method that takes a SecureSocketOptions argument:如果要完全禁用 SSL/TLS,请使用带有 SecureSocketOptions 参数的 ConnectAsync() 方法:

await client.ConnectAsync(m_mailServer, 25, SecureSocketOptions.None);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM