通过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);
I am getting the error "Unable to read data from the transport connection" when sending an email using the SmtpClient. The error does not happen when I am running this in Visual Studio. The error only happens when it is running in IIS. Below is my code:
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终是SMTP服务器的问题。集群中的电子邮件服务器之一是遇到问题。
It ended up being an issue with the SMTP server. One of the email servers in the cluster was having an issue.