hi everyone again ,
im making a program that sending a mail..
here i wants
1.save richtextbox as any txt file anywhere in my computer
2.add Attachment (that txt file) to my mail
3.send mail (without mailbody, only attachment file)
4.Delete txt file
Problem is Deleting file. I can not close the smtpClient , it is using txt file so im getting error "IOException was unhandled , file using with other programs.... "
i tried Dispose() isnt working and there is no Close()..
Here my codes;
i assumed problem is streamwriter at first but , i tried this code in other programs and it works ,
this means problem is smtpclient. it is using my file so i cant delete it.
how can i close smtpClient or is there other ways to make what i wants?
(sorry about my english)
im making a program that sending a mail..
here i wants
1.save richtextbox as any txt file anywhere in my computer
2.add Attachment (that txt file) to my mail
3.send mail (without mailbody, only attachment file)
4.Delete txt file
Problem is Deleting file. I can not close the smtpClient , it is using txt file so im getting error "IOException was unhandled , file using with other programs.... "
i tried Dispose() isnt working and there is no Close()..
Here my codes;
PHP Code:
Dim filename As String = "\" + Today + ".txt"
Dim foldername As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
Dim path As String = String.Concat(foldername, filename)
Dim write As IO.StreamWriter = New IO.StreamWriter(path)
write.Write(RichTextBox1.Text)
write.Dispose()
write.Close()
Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress("mymail")
MyMailMessage.To.Add("anymail")
MyMailMessage.Subject = ("mail subject")
MyMailMessage.Attachments.Add(New Attachment(path))
MyMailMessage.Body = ("")
MyMailMessage.SubjectEncoding = System.Text.Encoding.UTF8
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("mymail", "mypass")
SMTPServer.EnableSsl = True
SMTPServer.Send(MyMailMessage)
SMTPServer.Dispose()
IO.File.Delete(path) ' this code doesnt work
MsgBox("Sent")
PHP Code:
Dim path As String = "F:\text.txt"
Dim write As IO.StreamWriter = New IO.StreamWriter(path)
write.Write(RichTextBox1.Text)
write.Dispose()
write.Close()
IO.File.Delete(path)
how can i close smtpClient or is there other ways to make what i wants?
(sorry about my english)