I am currently debugging a problem and cannot find the answer to this question in the MSDN documentation
I have the following code:
if(attachmentFileName != null && File.Exists(attachmentFileName)) { mail.Attachments.Add(new Attachment(attachmentFileName, MediaTypeNames.Application.Octet)); } using(SmtpClient smtp = new SmtpClient { UseDefaultCredentials = true }) { try { smtp.Send(mail); } catch(SmtpException ex) { if(attachmentFileName != null && ex.StatusCode == SmtpStatusCode.ExceededStorageAllocation) {
At a higher level (calling this method), I have the following:
try { SendEmail(recipients, alertTitle, body, alertID, subjectPrefix, merchantIDValue, attachmentFilePath); } finally { if(tempFile != null) { File.Delete(tempFile); } }
I deployed the code in our test environment, and now I get the following exception in our error logs:
System.IO.IOException: The process cannot access the file 'C:\fileName.zip' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.Delete(String path) at AlertDelivery.CreateAttachmentFile(String attachmentData, String merchantID, String reportTitle) in d:\svn\trunk\Solution\Alerting\AlertDelivery.cs:line 143 at AlertDelivery.TrySendAlert(String merchantID, String reportTitle, Int32 alertID, String alertTitle, String attachmentData, String attachmentFilePath, String body, Boolean isReport, String subjectPrefix, List`1 recipients) in d:\svn\trunk\Solution\Alerting\AlertDelivery.cs:line 110 at AlertingService.ProcessAlertEvents(Object parameters) in d:\svn\trunk\Solution\Alerting\AlertingService.cs:line 174
Line 174 is the line File.Delete(tempFile); in the caller code.
Does SmtpClient support asynchronous attachment blocking after SmtpClient.Send been called? Any other noticeable issues?