troubleshooting Question

Sending email with attachments locks attached file when sending fails - VB.NET 2.0

Avatar of Elucid8
Elucid8 asked on
.NET ProgrammingASP.NETVisual Basic.NET
3 Comments1 Solution316 ViewsLast Modified:
Hi Experts,

I have created a webservice which does some processing from a DB into a CSV file and attempts to email that file. It is to be scheduled to run every day.

The problem I have is, at the moment on the web server I am deploying it to, the email sending fails and locks the file I am sending. Therefore the next time the process runs it fails due to the file still being locked. Is there anyway to make sure the file does not get locked even if the email fails?

I am using VB.NET 2.0 and VS2005.

Here is the code I use to send the mail if it helps:

            myMail.From = myMailFrom
            myMail.To.Add(myMailTo)
            myMail.Subject = strSubject
            If strPriority = "High" Then
                myMail.Priority = MailPriority.High
            Else
                myMail.Priority = MailPriority.Normal
            End If
            myMail.IsBodyHtml = True
            myMail.Body = strMessage
            If Not AttachmentFiles Is Nothing Then
                iCnt = AttachmentFiles.Count - 1
                For i = 0 To iCnt
                    If FileExists(AttachmentFiles(i)) Then myMail.Attachments.Add(New Attachment(AttachmentFiles(i)))
                Next
            End If

            Dim MailObj As New System.Net.Mail.SmtpClient
               MailObj.Host = System.Configuration.ConfigurationManager.AppSettings("smtpHost")
               MailObj.Send(myMail)

Thanks for any help you can give me!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros