通过SmtpClient发送邮件-无法从传输连接读取数据



我收到错误"无法从传输连接读取数据";使用SmtpClient发送电子邮件时。当我在Visual Studio中运行此操作时,不会发生错误。该错误仅在IIS中运行时发生。下面是我的代码:

System.Net.ServicePointManager.Expect100Continue = false;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler);
SmtpClient SmtpServer = new SmtpClient(_serviceSettings.SMTPServer, _serviceSettings.SMTPPort);
SmtpServer.Port = _serviceSettings.SMTPPort;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(_serviceSettings.SMTPUser, _serviceSettings.SMTPPass);

MailMessage mail = new MailMessage();
mail.From = new MailAddress(_serviceSettings.SMTPUser);
mail.To.Add(_serviceSettings.SMTPErrorTo);
mail.Subject = "Error Message";
mail.Body = errorMessage;
SmtpServer.EnableSsl = _serviceSettings.SMTPUseSSL;
SmtpServer.Send(mail);

结果是SMTP服务器出了问题。群集中的一个电子邮件服务器有问题。

相关内容

最新更新