I have an application that monitors a folder for incoming files then emails them out. The problem is it locks the file and It can't be deleted.
It sends the email fine, but once sent, it retains the handle to that file and won't release it.
I want to immediately delete the file after I send it. I've tried both Emailserver.SendAsync and Emailserver.send and both lock the file.
Any ideas how to release the lock?
Public Sub sendSMTP(ByVal strMsg As String, ByVal strTo As String, ByVal strSubject As String, ByVal strFile As String)
Dim EmailServer As New System.Net.Mail.SmtpClient(Me.SMTPGW)
Dim EmailMessage As New System.Net.Mail.MailMessage(Me.EmailFrom, strTo, strSubject, strMsg)
Dim attachment As New System.Net.Mail.Attachment(strFile)
Catch ex As Exception