c# - System.Net.Mail.SmtpException : Insufficient system storage. 服务器响应为: 4. 3.1 系统资源不足

标签 c# exchange-server system.net.mail smtpexception

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

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

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

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

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

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);
     }
 }

最佳答案

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

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

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

这是 Exchange Status Codes 的列表及其含义。

关于c# - System.Net.Mail.SmtpException : Insufficient system storage. 服务器响应为: 4. 3.1 系统资源不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692376/

相关文章:

c# - 如何比较多维数组是否相等?

c# - bool 逻辑/真值表和输出

c# - 以不存在的邮件帐户作为发件人发送邮件

c# - 为什么生成 PDF 后 Excel 不关闭?

c# - 通过 C# 交换 PowerShell 命令

spring - 有没有办法从 CXF 中的 JAX-RS REST 资源访问 CXF 消息交换?

c# - PowerShell 参数绑定(bind)异常

c# - 使用 C# ASP.NET 3.5 System.Net.Mail 发送大附件

c# - System.Net.Mail 发送超时

c# - 可以从 Javascript 文件访问 MVC ViewBag 对象吗?