Sending mail with vb.net (VSS2013) using gmail
Posted on 2014-11-12
I am trying to send mail using VB.Net and gmail.
I can get the program to work through my regular email provider, but with gmail it fails
The code is as follows:-
MailMessage.From = New MailAddress(EmailSender)
MailMessage.CC.Add(New MailAddress(EmailSender)) ' Copy to the sender
MailMessage.Subject = "Auto-Email from Comtass SQL Potato Trading System"
MailMessage.Body = "Haulage Advice for Load Card ABC0123"
Dim SmtpClient As New SmtpClient()
SmtpClient.Host = "smtp.gmail.com"
SmtpClient.Credentials = New Net.NetworkCredential(Username, Password)
SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpClient.EnableSsl = True
SmtpClient.Port = 587
Label3.Text = "Copy Sent to " & EmailSender
Catch ex As Exception
MsgBox("An Error has Occured - " & ex.Message & vbCrLf _
& " The Email has Not been Succcessful. Please Retry")
If I try port 456 the program hangs for a while then comes back with the message "An error has occurred - failure sending mail. The email has not been successful. please re-try"
If I try port 576 it immediately comes back with a an error "the SMTP connection requires a secure client or the client was not authenticated "
I'm tearing my hair out!!