How can I bypass smtp server certificate validation in .Net Core 2.2?
using System;
using System.Net;
using System.Net.Mail;
namespace EmailTest
{
internal static class Program
{
static void Main(string[] args)
{
SmtpClient client = new SmtpClient("192.168.0.10", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("username", "p4ssw0rd");
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("username@example.com");
mailMessage.To.Add("customer@example.com");
mailMessage.Body = "test email from dotnet core";
mailMessage.Subject = "subject";
client.Send(mailMessage);
}
}
}
I already tried
System.Net.ServicePointManager.ServerCertificateValidationCallback = (x, y, z, t) => true;
Which had no effect.
I also have already looked at the answers to this question, they all are about System.Net.Http.HttpClient
. I am asking whether there is a way to bypass certificate validation for System.Net.Mail.SmtpClient
.