通过SMTPClient获得错误发送邮件 - 无法从传输连接中读取数据

发布于 2025-01-28 06:27:35 字数 1189 浏览 3 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_蜘蛛 2025-02-04 06:27:35

最终是SMTP服务器的问题。集群中的电子邮件服务器之一是遇到问题。

It ended up being an issue with the SMTP server. One of the email servers in the cluster was having an issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文