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:
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 = newSmtpClient())
{
//client.CheckCertificateRevocation = false;
//client.ServerCertificateValidationCallback = (s, c, h, e) => true;
awaitclient.ConnectAsync(_emailConfiguration.SmtpServer, _emailConfiguration.SmtpPort, SecureSocketOptions.Auto);
awaitclient.AuthenticateAsync(_emailConfiguration.SmtpUsername, _emailConfiguration.SmtpPassword);
awaitclient.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
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://www.cnblogs.com/zengxiangzhan/p/14774394.html
内容来源于网络,如有侵权,请联系作者删除!