[英]System.Net.Mail.SmtpException: Insufficient system storage. The server response was: 4.3.1 Insufficient system resources
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. 我最近在C#中设计了一个程序,它将从SQL数据库中提取信息,编写带有结果的HTML页面,并自动发送电子邮件。 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: 在程序的前几次成功运行之后,我将开始获得此异常:
Base exception: System.Net.Mail.SmtpException: Insufficient system storage. 基本异常:System.Net.Mail.SmtpException:系统存储不足。 The server response was: 4.3.1 Insufficient system resources 服务器响应如下:4.3.1系统资源不足
I'm wondering if I should be calling some sort of Dispose()-like method in my mailing? 我想知道我是否应该在我的邮件中调用某种类似Dispose()的方法? 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. 这会影响我们公司的所有客户,而不仅仅是我的代码。
This is Exchange 2010, and my code is compiled against .NET 3.5. 这是Exchange 2010,我的代码是针对.NET 3.5编译的。 My attachments are typically 27kb. 我的附件通常是27kb。 If I log into the exchange server, it seems that messages just stick in a queue indefinitely. 如果我登录到Exchange服务器,似乎消息只是无限期地挂在队列中。 Clearing out the queue (remove without sending NDR) and rebooting the server will get it going again. 清除队列(删除而不发送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);
}
}
This error can happen when: 在以下情况下会发生此错误
It is more common to run into issue #2 than issue #1. 遇到问题#2比问题#1更常见。
Here is a list of Exchange Status Codes and their meanings. 以下是Exchange状态代码及其含义的列表。
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. 为了最终缩小问题的范围,你可以交换一个不同的邮件客户端,比如aspNetEmail(你可以得到一个eval版本来测试),它不需要几行代码。 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. 您可以通过查看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建议观察磁盘空间。
In exchange 2007 the c: (system drive) needs about 4GB of free disk space. 在Exchange 2007中,c :(系统驱动器)需要大约4GB的可用磁盘空间。 This was our problem. 这是我们的问题。 Increment the drive and the mails will flow again. 增加驱动器,邮件将再次流动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.