Author Topic: Emailer threading  (Read 4268 times)

M4

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Emailer threading
« Reply #30 on: July 04, 2017, 02:05:36 AM »
Hi Archie,
I am still having the same issue
Any update on this will be much appreciated.
Thanks
Manoj

Phrog30

  • Guest
Re: Emailer threading
« Reply #31 on: July 04, 2017, 09:05:00 AM »
Wrap the send command in a try,catch block, this will prevent the app from "crashing".  The error you are getting is probably in your email settings.  I suggest searching the web for your exact problem, there are tons of info out.  You mention you are still having problems, but this is your first post.  I have successfully emailed using Gmail with no problems, here is the code and settings that I used:

Code: [Select]
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Email_Thread = New Thread(AddressOf Email)
        Email_Thread.IsBackground = True
        Email_Thread.Start()

    End Sub

    Private Sub Email()

        Using mail As New MailMessage
            Try
                mail.From = New MailAddress("xxxxxxxxxxx@gmail.com") 'Your email
                mail.To.Add(txt_Email_To.Text) ' Address to send to...
                mail.Body = txt_Email_Body.Text
            Catch
            End Try

            mail.Subject = txt_Email_Subject.Text
            mail.IsBodyHtml = False
            mail.Priority = MailPriority.Normal
            Using SMTP As New SmtpClient
                SMTP.EnableSsl = True
                SMTP.Port = "587"
                SMTP.Host = "smtp.gmail.com"
                SMTP.UseDefaultCredentials = False
                SMTP.DeliveryMethod = SmtpDeliveryMethod.Network
                SMTP.Credentials = New Net.NetworkCredential("xxxxxxxx@gmail.com", "password") 'Enter your email and password

                Try
                    SMTP.Send(mail)
                Catch ex As Exception
                    MsgBox(ex.Message)
                    Return
                End Try

                Email_Success()

            End Using
        End Using

    End Sub

    Private Sub Email_Success()

        MsgBox("Email has been sent successfully!")

    End Sub

You obviously will need to replace "xxxxxxxx@gmail.com" with your email and "password" with your password.