File locked after sending it as attachment

前端 未结 6 1435
-上瘾入骨i
-上瘾入骨i 2020-12-10 13:20

I am sending a file as an attachment:

            // Create  the file attachment for this e-mail message.
            Attachment data = new Attachment(filePa         


        
6条回答
  •  暖寄归人
    2020-12-10 13:34

    Disposing your message will fix this for you. Try calling Dispose on your message before moving the file, like so:

    message.Dispose();
    File.Move(...)
    

    When disposing MailMessage, all locks and resources are released.

提交回复
热议问题