Friday, 28 March 2008
System.Net.Mail and locked files
For many years now I have had a functional class for making it easy to create and send emails. I have over the years tweaked this class to support lots of additional features such as html and plain text templates, sending emails using alternate views, file attachments etc.
However just recently I noticed that if I tried to do anything with a file after I had attached it to an email using my mailmanager class then I got problems as Windows was always retaining a file lock on the file.
The solution was a simple one...write better code. Essentially I was not correctly disposing of the System.Net.Mail.MailMessage after attaching files and sending the email. Its a lesson in diligence that sometimes it doesn't matter how many times you have revised a piece of code over the years. It can be the simplest of things that bites you!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Please leave a comment if you have found this post useful, or if there are any errors. I will do my best to assist if a posted solution does not help with your problem.