I have one problem. Please help me to sort out this.
I am send email with attachments. It is working fine.
I want to do is that, after sending the mail, I want to move the files which i attached to the mail from it's original location to other location in my hard drive.
But When I am doing this, It gives me the exception "File is already in use by another process"
SendMessageWithAttachment() this method actually send the mail.
public static string SendMessageWithAttachment(string sendTo, string sendFrom, string sendSubject, string sendMessage, ArrayList attachments)
message = new MailMessage(
foreach (string attach in attachments)
Attachment attached = new Attachment(attach, MediaTypeNames.Application.Octet);
client = new SmtpClient(Properties.Settings.Default.SMTPAddress);
return "Message sent to " + sendTo + " at " + DateTime.Now.ToString() + ".";
catch (Exception ex)
Here I am invoking the above method
ArrayList sendAttachments = new ArrayList(Directory.GetFiles("InProcess Mails"));
string status = Emailer.SendMessageWithAttachment(sendTo, sendFrom, sendSubject, sendMsgBody, sendAttachments);
MessageBox.Show(status, "Email Status");
foreach (string str in sendAttachments)
File.Move(str, "SentMail\\" + str.Substring(str.LastIndexOf('\\'))); <--- This is the line where exception is through
2. Edit your posts, don't double-post
3. Please use code-tags. (["code"] and [/"code"] without the quotes)
Outlook has a habit of keeping a handle on any file it uses until it (Outlook) is closed and reopened. I know that it does this with .msg files which I used in an application not too long ago. My solution was to copy the .msg file to another location before opening it. I don't know if this is the same with the SmtpClient, but I suggest you copy the attachment files before attaching them to an e-mail and see if the error is still occurring. If it is, the problem lies elsewhere