FluentEmail icon indicating copy to clipboard operation
FluentEmail copied to clipboard

How to ignore a invalid certificate?

Open tobecwb opened this issue 7 years ago • 2 comments

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

tobecwb avatar Apr 16 '18 19:04 tobecwb

.netcore 2.0 has the ServicePointManager class. Looks like you'd set the ServerCertificateValidationCallback on it

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

mickeyr avatar Apr 25 '18 14:04 mickeyr

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.

mickeyr avatar Apr 25 '18 14:04 mickeyr