asp.net-mvc – MVCMailer SendAsync和删除附件
发布时间:2020-12-16 09:45:43 所属栏目:asp.Net 来源:网络整理
导读:在异步发送电子邮件后,我无法让MVCMailer删除附件. 我无法弄清楚如何处理消息以释放附加到消息附件的进程. 按照说明here …. private IUserMailer userMailer = new UserMailer(); public IUserMailer UserMailer { get { return this.userMailer; } set { t
在异步发送电子邮件后,我无法让MVCMailer删除附件.
我无法弄清楚如何处理消息以释放附加到消息附件的进程. 按照说明here …. private IUserMailer userMailer = new UserMailer(); public IUserMailer UserMailer { get { return this.userMailer; } set { this.userMailer = value; } } using (SmtpClientWrapper client = new SmtpClientWrapper()) { client.SendCompleted += (sender,e) => { if (e.Error != null || e.Cancelled) { // Handle Error } //Use e.UserState //?? How can I use the userstate?? There are no // instructions?? // Delete the saved attachments now. // This will not work since the mailmessage process // is still attached. Parallel.ForEach(imageList,image => { if (System.IO.File.Exists(image)) { System.IO.File.Delete(image); } }); }; // SendAsync() extension method: using Mvc.Mailer // farm is my model imageList is a list of file locations for the // uploaded attachments UserMailer.Submission(farm,imageList).SendAsync("user state object",client); } 解决方法
您可以在使用语句中运行中断SmtpClientWrapper,并在清理附件之前手动调用dispose.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- asp.net-mvc – 多个模型和Breeze上下文的元数据
- 启用禁用按钮asp .net – 使用javascript
- asp.net-mvc – 避免在Web Publish上删除文件夹
- asp.net-mvc-2 – 我的Asp.Net C#类如何返回一个
- 为什么从ASP.NET页面下载时,.docx文件被损坏?
- ASP.NET ReportViewer Google Chrome CPU使用情况
- asp.net – 在某些情况下如何覆盖/更改FormsAuth
- 使用 xUnit 编写 ASP.NET Core WebAPI单元测试
- asp.net – 隐藏字段vs viewstate
- asp.net-mvc-3 – MVC3 – 使用Entity框架设置Co
热点阅读