FluentEmail
FluentEmail copied to clipboard
How to ignore a invalid certificate?
I have a server with a self-signed certificate (my email client consider this a invalid certificate, and FluentEmail too).
How can I send a email ignoring the invalid certificate? tried the following code:
var email = Email
.From("[email protected]", "Me")
.To(message.Destination)
.Subject(message.Subject)
.Body(message.Body);
email.Sender = new SmtpSender(new SmtpClient("smtp.server.com", 587)
{
Credentials = new NetworkCredential("username", "password"),
EnableSsl = false
});
await email.SendAsync();
I always receive the error The remote certificate is invalid according to the validation procedure
.netcore 2.0 has the ServicePointManager class. Looks like you'd set the ServerCertificateValidationCallback on it
ServicePointManager.ServerCertificateValidationCallback =
(sender, certificate, chain, sslPolicyErrors) => true;
Also, if you want to disable SSL, on the current version you have to set the UseSsl flag on the SmtpSender class. It overrides the SmtpClient setting.