I am getting error when I am putting my sendmail function into other thread.
But without threading the message was sent successfully.
I am getting error in this part when sending using thread.
mail.Body = EmailBody.DocumentText
It say: Specified cast is not valid.
Here is my code for sending email
EmailBody is a webbrowser in Desing MOde ON
And this is how I start the thread and call the sendmailCode:Private Sub SendMail() Try Dim SmtpServer As New SmtpClient() Dim mail As New MailMessage() SmtpServer.Credentials = New _ Net.NetworkCredential("username", "password") SmtpServer.Port = 587 SmtpServer.EnableSsl = True SmtpServer.Host = "pod51003.outlook.com" mail = New MailMessage() mail.From = New MailAddress("email") mail.To.Add("toemail") mail.CC.Add("CCemail") mail.Subject = "Test Mail" mail.IsBodyHtml = True mail.Body = EmailBody.DocumentText SmtpServer.Send(mail) TSSLstatus.Text = "Email successfully sent...." Me.Cursor = Cursors.Arrow MsgBox("mail send") Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
What I am missing for?Code:Private Sub btnSend_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click TSSLstatus.Text = "Please wait, sending email..." Dim t As Thread t = New Thread(AddressOf Me.SendMail) t.Start() End Sub
I need to put in other thread so that my Form is active while sending big email.




Reply With Quote