I recently developed a C # program that will extract information from SQL databases, write an HTML page with the results, and automatically send it by email. Everything works for me [sporadically], the problem that I am facing is that I seem to be breaking the exchange server of our company. After the first few successful launches of the program, I will begin to receive this exception:
Basic exception: System.Net.Mail.SmtpException: insufficient system storage. Server response: 4.3.1 Not enough system resources
I am wondering if I should call some Dispose () method in my newsletter? Or, if there is some other obvious reason why I will force the mail system to stop responding? This applies to all customers in our company, not just my code.
This is Exchange 2010, and my code is compiled with .NET 3.5. My attachments are usually 27kb. If I log into the exchange server, it seems that the messages just remain in the queue for an indefinite period. Clearing the queue (deleting without sending NDR) and restarting the server will start again.
The mailing parts are as follows (username, password and address are 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";
raney source share