【发布时间】:2013-03-10 16:03:18
【问题描述】:
我创建了一个应用程序,它可以根据数据库中的信息生成 excel 文件。这些文件保存在我的硬盘上的一个文件夹中。
然后我附上文件并通过邮件发送它们。当我生成另一批文件时,我删除旧文件,然后创建新文件。
我的问题是,当我生成了一批文件然后发送它们,我想生成另一批文件时,我无法删除其中一个旧文件,因为邮寄方式仍在保留其中一个 excel 文件.
这是我的代码:
public void SendMailedFilesDKLol() {
string[] sentFiles=Directory.GetFiles(some_Folder);
if(sentFiles.Count()>0) {
System.Net.Mail.SmtpClient client=new System.Net.Mail.SmtpClient("ares");
System.Net.Mail.MailMessage msg=new System.Net.Mail.MailMessage();
msg.From=new MailAddress("system@lol.dk");
msg.To.Add(new MailAddress("lmy@lol.dk"));
msg.Subject="IBM PUDO";
msg.Body=
sentFiles.Count()+" attached file(s) has been sent to the customer(s) in question ";
msg.IsBodyHtml=true;
foreach(string file in sentFiles) {
Attachment attachment=new Attachment(file);
msg.Attachments.Add(attachment);
}
client.Send(msg);
}
}
我曾尝试处理客户端元素,但没有帮助。
谁能帮我解决这个问题?
【问题讨论】:
-
您确定是您的邮件代码而不是 Excel 进程保留了您的文档?
-
是的,我是,因为当我注释掉邮件发送方法时,我可以根据需要重新生成文件
标签: c# .net smtp mailmessage