System.Net.Mail.SmtpException:系统存储不足。 服务器响应如下:4.3.1系统资源不足

我最近在C#中设计了一个程序,它将从SQL数据库中提取信息,编写带有结果的HTML页面,并自动发送电子邮件。 我一切都在工作[偶尔],我遇到的问题是我似乎正在崩溃我们公司的交换服务器。 在程序的前几次成功运行之后,我将开始获得此exception:

基本exception:System.Net.Mail.SmtpException:系统存储不足。 服务器响应如下:4.3.1系统资源不足

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

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

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

public void doFinalEmail() { List distList = new List(); 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); } } 

在以下情况下会发生此错误

  1. Exchange服务器磁盘空间不足。
  2. 收件人邮箱磁盘空间不足。

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

以下是Exchange状态代码及其含义的列表。

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

如果这确实是服务器上的问题(SMTP日志显示干净连接并且问题可以与备用客户端一起复制),那么我将登录到服务器(如果您可以访问),并按照jeuton建议观察磁盘空间。

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