C# System.Net.Mail.SmtpException: 系统存储空间不足。服务器响应为:4.3.1 系统资源不足

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14692376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:41:26  来源:igfitidea点击:

System.Net.Mail.SmtpException: Insufficient system storage. The server response was: 4.3.1 Insufficient system resources

c#exchange-serversystem.net.mailsmtpexception

提问by raney

I've recently designed a program in C# that will pull information from SQL databases, write an HTML page with the results, and auto-email it out. I've got everything working [sporadically], the problem I'm having is that I seem to be crashing our company's exchange server. After the first few successful runs of the program, I'll start getting this exception:

我最近用 C# 设计了一个程序,该程序将从 SQL 数据库中提取信息,编写带有结果的 HTML 页面,并自动通过电子邮件发送出去。我已经让一切正常[偶尔],我遇到的问题是我似乎使我们公司的交换服务器崩溃。在程序的前几次成功运行后,我将开始收到此异常:

Base exception: System.Net.Mail.SmtpException: Insufficient system storage. The server response was: 4.3.1 Insufficient system resources

基本异常:System.Net.Mail.SmtpException:系统存储空间不足。服务器响应为:4.3.1 系统资源不足

I'm wondering if I should be calling some sort of Dispose()-like method in my mailing? Or if there is any other apparent reason that I would be causing the mail system to stop responding? This affects all clients in our company, not just my code.

我想知道我是否应该在邮件中调用某种类似 Dispose() 的方法?或者,如果有任何其他明显的原因会导致邮件系统停止响应?这会影响我们公司的所有客户,而不仅仅是我的代码。

This is Exchange 2010, and my code is compiled against .NET 3.5. My attachments are typically 27kb. If I log into the exchange server, it seems that messages just stick in a queue indefinitely. Clearing out the queue (remove without sending NDR) and rebooting the server will get it going again.

这是 Exchange 2010,我的代码是针对 .NET 3.5 编译的。我的附件通常是 27kb。如果我登录到交换服务器,似乎消息只是无限期地留在队列中。清除队列(删除而不发送 NDR)并重新启动服务器将使其再次运行。

The mailing portions look like this (username, password, and address changed):

邮件部分如下所示(用户名、密码和地址已更改):

public void doFinalEmail()
{
     List<string> distList = new List<string>();
     string distListPath = Environment.CurrentDirectory + "\DistList.txt";
     string aLine;

     logThat("Attempting email distribution of the generated report.");

     if (File.Exists(distListPath))
     {
         FileInfo distFile = new FileInfo(distListPath);
         StreamReader distReader = distFile.OpenText();

         while (!String.IsNullOrEmpty(aLine = distReader.ReadLine()))
         {
             distList.Add(aLine);
         }
     }
     else
     {
         logThat("[[ERROR]]: Distribution List DOES NOT EXIST! Path: " + distListPath);
     }

     MailMessage msg = new MailMessage();
     MailAddress fromAddress = new MailAddress("emailaddresshere");
     msg.From = fromAddress;

     logThat("Recipients: ");
     foreach (string anAddr in distList)
     {
         msg.To.Add(anAddr);
         logThat("\t" + anAddr);
     }
     if (File.Exists(Program.fullExportPath))
     {
         logThat("Attachment: " + Program.fullExportPath);
         Attachment mailAttachment = new Attachment(Program.fullExportPath);
         msg.Attachments.Add(mailAttachment);
         string subj = "Company: " + Program.yestFileName;
         msg.Subject = subj;
         msg.IsBodyHtml = true;
         msg.BodyEncoding = System.Text.Encoding.UTF8;
         sendMail(msg);
     }
     else
     {
         logThat("[[ERROR]]: ATTACHMENT DOES NOT EXIST! Path: " + Program.fullExportPath);
     }
 }

 public void sendMail(MailMessage msg)
 {
     try
     {
         string username = "user"; //domain user
         string password = "pass"; // password
         SmtpClient mClient = new SmtpClient();
         mClient.Host = "192.168.254.11";
         mClient.Credentials = new NetworkCredential(username, password);
         mClient.DeliveryMethod = SmtpDeliveryMethod.Network;
         mClient.Send(msg);
     }
     catch (Exception oops)
     {
         string whatHappened = String.Format("Company: \r\nFailure in {0}! \r\n\r\nError message: {1} \r\nError data: {2} \r\n\r\nStack trace: {3} \r\n\r\nBase exception: {4} \r\nOccuring in method: {5} with a type of {6}\r\n", oops.Source, oops.Message, oops.Data, oops.StackTrace, oops.GetBaseException(), oops.TargetSite, oops.GetType());
         logThat(whatHappened);
         Environment.Exit(1);
     }
 }

采纳答案by jeuton

This error can happen when:

在以下情况下可能会发生此错误:

  1. The exchange server is out of disk space.
  2. The recipient mailbox is out of disk space.
  1. Exchange 服务器磁盘空间不足。
  2. 收件人邮箱磁盘空间不足。

It is more common to run into issue #2 than issue #1.

遇到问题 #2 比问题 #1 更常见。

Here is a list of Exchange Status Codesand their meanings.

这是交换状态代码及其含义的列表。

回答by J.T. Taylor

To narrow down the issue definitively, you could swap in a different mail client like aspNetEmail (you can get an eval version to test), it wouldn't take but a few lines of code. If the problem persists, it is on the server; if not, it is on the client. I would strongly suspect this is a problem on the server, however, as when the client closes the connection and the message is sent, the server should really not be holding any resources as a result of that connection. You could verify this by looking at your SMTP logs and making sure there was no SMTP error when the connection was closed.

要明确缩小问题的范围,您可以换入一个不同的邮件客户端,如 aspNetEmail(您可以获得一个 eval 版本进行测试),只需几行代码即可。如果问题仍然存在,则是在服务器上;如果没有,它在客户端上。我强烈怀疑这是服务器上的问题,但是,因为当客户端关闭连接并发送消息时,服务器实际上不应该因为该连接而持有任何资源。您可以通过查看 SMTP 日志并确保在连接关闭时没有 SMTP 错误来验证这一点。

If this is indeed a problem on the server (the SMTP log shows clean disconnection and the problem is replicable with an alternate client), then I would log onto the server (if you can get access), and watch the disk space as jeuton suggests.

如果这确实是服务器上的问题(SMTP 日志显示完全断开连接,并且该问题可通过备用客户端复制),那么我将登录服务器(如果您可以访问),并按照 jeuton 的建议观察磁盘空间.

回答by Jo?o Pereira Oliveira

In exchange 2007 the c: (system drive) needs about 4GB of free disk space. This was our problem. Increment the drive and the mails will flow again.

作为交换,2007 年的 c:(系统驱动器)需要大约 4GB 的可用磁盘空间。这是我们的问题。增加驱动器,邮件将再次流动。