Results 1 to 8 of 8

Thread: [RESOLVED] Threading and Sending Mail

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Resolved [RESOLVED] Threading and Sending Mail

    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
    Code:
    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
    And this is how I start the thread and call the sendmail

    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
    What I am missing for?
    I need to put in other thread so that my Form is active while sending big email.
    Last edited by dr_aybyd; Nov 25th, 2010 at 01:04 AM.
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width