在异步发送电子邮件后,我无法让 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);
}