Powershell Email Locks attachment

I came across an issue when I was trying to manipulate a file which I had just emailed using the standard email code which is on multiple places on the web.

All descriptions on the web (that I have seen) which show how to do this so far have left the email attachment open which means if the script is continuing after the email and you wish to use the file you have attached you will not be able to as it will show as locked, use this example to close the attached file correctly using .Dispose()

Thanks to Jaykul on the Powershell IRC channel.

2 thoughts on “Powershell Email Locks attachment”

  1. No problem, I think most people send the email as the last thing with the results, its only because I needed to work with the file that I found this out.

    Glad it helped someone else !

  2. Thanks for posting that. I looked everywhere for this. Like you said almost all the examples left the attachment locked.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.