question

PostAlmostAnything-1364 avatar image
0 Votes"
PostAlmostAnything-1364 asked PostAlmostAnything-1364 commented

ASP.Net Core Site Stops Sending Emails Citing Mysterious SSL Issue

What might suddenly make it impossible for a .Net 5 website to stop sending email citing the following:

 An unhandled exception occurred while processing the request.
 InvalidOperationException: 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:
 • A required certificate is not within its validity period when verifying against the current system clock or the timestamp in the signed file.
 MySite.Pages.contact.IndexModel.SendEmailAdmin(string name, string email, string subject, string message) in Index.cshtml.cs, line 143
dotnet-aspnet-core-generaldotnet-aspnet-core-razor
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please share the code with us !

0 Votes 0 ·

Sure, but I've since noticed that the AutoSSL feature of the mail server is issuing certificates that expire in a matter of hours. I think that is probably the problem since every other cPanel account that hosts mail for sites physically hosted on the same Windows server as this one don't have the problem. I would like to know if I am on the right track and need to move my inquiry to the cPanel site.

Is there a way to tell .Net to send emails no matter what even if the SSL certificate is technically expired?

My code includes the following which has ALWAYS worked fine:

 using (SmtpClient client = new SmtpClient())
             {
                 await client.ConnectAsync("mail.example.com", 587, useSsl: false);
                 await client.AuthenticateAsync("noreply@example.com", "mypw");
                 await client.SendAsync(msg);
                 await client.DisconnectAsync(quit: true);
             }


0 Votes 0 ·
rebin avatar image rebin PostAlmostAnything-1364 ·

Try to ignore certificate errors as @AlexanderNulensFinvisionBrussels-6234 mentioned in the comment.

    ServicePointManager.ServerCertificateValidationCallback = errorCertHandler;
        
     private bool errorCertHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors error)
            
        {
        
             return true;
        } 



0 Votes 0 ·

Also, I still think that despite the expired cert this is a problem with .Net Core because I can still use Outlook to send/receive emails from that server despite the expired cert. This indicates that somebody built something into .Net which won't allow it to send mail to servers with expired certs.

Again, can you force .Net to send messages anyway or disable the SSL check?

0 Votes 0 ·
Bruce-SqlWork avatar image Bruce-SqlWork PostAlmostAnything-1364 ·

it is the SmtpClient that needs to support invalid certificates. it is also not recommended to use. if your hosting O/S supports, you can

 ServicePointManager.ServerCertificateValidationCallback = 
     (sender, certificate, chain, sslPolicyErrors) => true;

to disable all ssl verification.

1 Vote 1 ·
Show more comments

0 Answers