fallnwrld
February 6th, 2009, 04:45 PM
I have the .Net program sending an email and adding a file as an attachment
Private Sub SendSMTP(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String, ByVal strCC As String, ByVal strAttachments As String)
Dim insMail As New MailMessage(New MailAddress(strFrom), New MailAddress(strTo))
With insMail
.Subject = strSubject
.Body = strBody
'.CC.Add(New MailAddress(strCC))
If Not strAttachments.Equals(String.Empty) Then
Dim strFile As String
Dim strAttach() As String = strAttachments.Split(";"c)
For Each strFile In strAttach
.Attachments.Add(New Attachment(strFile.Trim()))
Next
strFile = Nothing
End If
End With
Dim smtp As New System.Net.Mail.SmtpClient
smtp.Host = strSMTP
smtp.Port = 25
smtp.Send(insMail)
smtp = Nothing
insMail = Nothing
strAttachments = Nothing
End Sub
When I tried to erase the file at the end it says the the file is still in use. I tried declaring the variables to nothing and still doesn't help. If I dont send the file in the email I can erase it with out a problem. Any suggestions?
Private Sub SendSMTP(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String, ByVal strCC As String, ByVal strAttachments As String)
Dim insMail As New MailMessage(New MailAddress(strFrom), New MailAddress(strTo))
With insMail
.Subject = strSubject
.Body = strBody
'.CC.Add(New MailAddress(strCC))
If Not strAttachments.Equals(String.Empty) Then
Dim strFile As String
Dim strAttach() As String = strAttachments.Split(";"c)
For Each strFile In strAttach
.Attachments.Add(New Attachment(strFile.Trim()))
Next
strFile = Nothing
End If
End With
Dim smtp As New System.Net.Mail.SmtpClient
smtp.Host = strSMTP
smtp.Port = 25
smtp.Send(insMail)
smtp = Nothing
insMail = Nothing
strAttachments = Nothing
End Sub
When I tried to erase the file at the end it says the the file is still in use. I tried declaring the variables to nothing and still doesn't help. If I dont send the file in the email I can erase it with out a problem. Any suggestions?