Hi,
Am trying to asynchronously send an email with an attachment using .net's SMPTClient class:
SmtpClient smtp = new SmtpClient(MailServer);
smtp.SendAsync(mailMsg, "");
smtp.SendCompleted += new SendCompletedEventHandler(MailSentCallback);
mailMsg.Dispose();
I need to delete the attachment file from my server as soon as the mail is successfully sent.
private static void MailSentCallback(object sender, AsyncCompletedEventArgs e)
{
File.Delete(myAttachment);
}
But when this method is called, am getting an error: "The process cannot access the file 'myAttachment' because it is being used by another process." Also, mail is not being delivered.If i use Send method instead of SendAsync, then mail delivery is working.
What am i missing here?
Thanks for reading!