My blog has moved!

You should be automatically redirected in 6 seconds. If not, visit
http://www.f5todebug.wordpress.com
and update your bookmarks.

Showing posts with label MailMessage. Show all posts
Showing posts with label MailMessage. Show all posts

Friday, 28 March 2008

System.Net.Mail and locked files

0 comments

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!