Reputation: 11
I am workin on project using asp.net core 3.1 , also i am using design pattern in my work.
when i try to send email using smtp i got this error .
An error occurred while attempting to establish an SSL or TLS connection. The server's SSL certificate could not be validated for the following reasons: • The server certificate has the following errors: • The revocation function was unable to check revocation for the certificate.
This is my code ...
using (var client = new SmtpClient())
{
try
{
await client.ConnectAsync(_mailSettings.Host, _mailSettings.Port, false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
await client.AuthenticateAsync(_mailSettings.UserName, _mailSettings.Password);
await client.SendAsync(mailMessage);
}
catch
{
throw;
}
finally
{
await client.DisconnectAsync(true);
client.Dispose();
}
}
the error happened after this line ...
await client.ConnectAsync(_mailSettings.Host, _mailSettings.Port, false);
Upvotes: 2
Views: 5754
Reputation: 38528
The revocation function was unable to check revocation for the certificate.
This is usually a transient error caused by the CRL server being offline or otherwise unreachable at the time when you tried to establish and SSL/TLS connection and so the SslStream
was unable to validate the server's SSL certificate.
The CRL server is the central authority that provides a way for clients to check if a certificate has been revoked or not.
You can disable certificate revocation checks using the following snippet of code before calling the Connect
method:
client.CheckCertificateRevocation = false;
For more information, see the documentation: http://www.mimekit.net/docs/html/P_MailKit_IMailService_CheckCertificateRevocation.htm
Upvotes: 9