MailKit在.NetCore5下发送邮件 An error occurred while attempting to establish an SSL or TLS connection
  EFYj8b4Hmg0O 2023年11月02日 48 0

MailKit An error occurred while attempting to establish an SSL or TLS connection

问题:

异常:An error occurred while attempting to establish an SSL or TLS connection.

This usually means that the SSL certificate presented by the server is not trusted by the system for one or more of

the following reasons:

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. A Certificate Authority CRL server for one or more of the certificates in the chain is temporarily unavailable.

4. The certificate presented by the server is expired or invalid.

5. The set of SSL/TLS protocols supported by the client and server do not match.

6. You are trying to connect to a port which does not support SSL/TLS.

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#SslHandshakeException for possible solutions.

MailKit at MailKit.Net.Smtp.SmtpClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, Boolean doAsync, CancellationToken cancellationToken)

MailKit  版本 2.12.0  Linux Centos 7.9  

源代码:

using (var client = new SmtpClient())
{
// client.CheckCertificateRevocation = false;
// client.ServerCertificateValidationCallback = (s, c, h, e) => true;
await client.ConnectAsync(_emailConfiguration.SmtpServer, _emailConfiguration.SmtpPort, SecureSocketOptions.Auto);
await client.AuthenticateAsync(_emailConfiguration.SmtpUsername, _emailConfiguration.SmtpPassword);
await client.SendAsync(mimeMessage);
await client.DisconnectAsync(true);
}


接收服务器:

imap.exmail.qq.com(使用SSL,端口号993)

发送服务器:

smtp.exmail.qq.com(使用SSL,端口号465)

解决方案:

openssl.cnf的配置问题

openssl_conf = openssl_init

[openssl_init]
ssl_conf = ssl_config

[ssl_config]
system_default = tls_defaults

[tls_defaults]
CipherString = @SECLEVEL=2:kEECDH:kRSA:kEDH:kPSK:kDHEPSK:kECDHEPSK:-aDSS:-3DES:!DES:!RC4:!RC2:!IDEA:-SEED:!eNULL:!aNULL:!MD5:-SHA384:-CAMELLIA:-ARIA:-AESCCM8
Ciphersuites = TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:TLS_AES_128_CCM_SHA256
MinProtocol = TLSv1.2





【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: apache-ab并发负载压力测试 下一篇: DRBD
  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  ehrZuhofWJiC   2024年05月17日   36   0   0 服务器linux
EFYj8b4Hmg0O