MVCMailer SendAsync 和删除附件
我在异步发送电子邮件后无法让 MVCMailer 删除附件。
我不知道如何处理该消息以释放附加到消息附件的进程。
按照此处的说明进行操作...
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);
}
I'm having trouble getting MVCMailer to delete attachments after sending an email asynchronously.
I can't figure out what to do to dispose of the message to free up processes attached to the message attachments.
Following the instructions 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在清理附件之前运行将 SmtpClientWrapper 从 using 语句中删除并手动调用 dispose。
You could run break the SmtpClientWrapper out of the using statement and call dispose on it manually just before you clean-up the attachment.
为了展示我的成功解决方案是:
To show what my successful solution was: