J
John
Hi
I am emailing a text file as attachment via the below code. The problem is
that after the file has been emailed, it becomes locked and can not be
accessed by further code such as IO.File.AppendAllText(FileName, Content)
which gives the error 'file is in use by another process' or something
similar. How can I release the file after it has been emailed or email it in
a way that it does not get locked?
Many Thanks
Regards
= Code Below ===========================
Dim Msg As String
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New
MailAddress(strTo))
MailMsg.BodyEncoding = System.Text.Encoding.Default
MailMsg.Subject = strSubject.Trim()
MailMsg.Body = strMessage.Trim() & vbCrLf
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
MailMsg.Attachments.Add(New System.Net.Mail.Attachment(Attachment))
Dim SmtpMail As New SmtpClient
SmtpMail.Host = My.Settings.SMTPServer
SmtpMail.Port = 25
SmtpMail.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
SmtpMail.Send(MailMsg)
SmtpMail = Nothing
MailMsg = Nothing
I am emailing a text file as attachment via the below code. The problem is
that after the file has been emailed, it becomes locked and can not be
accessed by further code such as IO.File.AppendAllText(FileName, Content)
which gives the error 'file is in use by another process' or something
similar. How can I release the file after it has been emailed or email it in
a way that it does not get locked?
Many Thanks
Regards
= Code Below ===========================
Dim Msg As String
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New
MailAddress(strTo))
MailMsg.BodyEncoding = System.Text.Encoding.Default
MailMsg.Subject = strSubject.Trim()
MailMsg.Body = strMessage.Trim() & vbCrLf
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
MailMsg.Attachments.Add(New System.Net.Mail.Attachment(Attachment))
Dim SmtpMail As New SmtpClient
SmtpMail.Host = My.Settings.SMTPServer
SmtpMail.Port = 25
SmtpMail.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
SmtpMail.Send(MailMsg)
SmtpMail = Nothing
MailMsg = Nothing