出现此问题通常是因为Exchange
服务器
的证书未被信任或已过期。
解决方案
是在发送电子邮件时禁用证书验证,代码示例如下:
using System.Net;
using System.Net.Mail;
public void SendEmail()
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
return true;
string smtpServer = "smtp.example.com";
int portNumber = 587;
string senderAddress = "sender@example.com";
string senderPassword = "password";
string recipientAddress = "recipient@example.com";
string subject = "Test";
string body = "This is a test email.";
MailMessage message = new MailMessage(senderAddress, recipientAddress, subject, body);
SmtpClient smtpClient = new SmtpClient(smtpServer, portNumber);
smtpClient.Credentials = new NetworkCredential(senderAddress, senderPassword);
smtpClient.EnableSsl = true;
smtpClient.Send(message);
在这个示例中,我们使用了一个委托来覆盖默认的证书验证机制,并将其设置为始终返回True。这将禁用证书验证并允许我们发送电子邮件。但请注意,这可能会降低安全性,请在确认服务商反复验证通过之前使用此方法。