I\'m attempting to use the System.Net.Mail.SmtpClient class to relay an email through my company\'s email server. All SMTP connections to the mail server have to be SSL and
If you want to be more secure, you might want to look at doing the following:
theClient.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
(sender, certificate, chain, sslPolicyErrors) => {
if (sender == theClient) {
return true;
} else {
// you should apply the code from this SO answer
// https://stackoverflow.com/a/25895486/795690
// if you find that anything in your app uses this path
throw new ApplicationException("Certificate validation is currently disabled, extra code neeeded here!");
}
};
In this code we are auto-approving certificates only for the specific SMTP client in question; we have a stub code path which you should upgrade to explicitly reinstate default certificate validation if you find that anything else in your app is using it.
Another different, useful approach to approving certificates only in contexts where you actually want to is in this SO answer.