I want to send an email, but it gives me an error.
I have this code:
Sub sendMail(ByVal title As String, ByVal content As String)
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 25)
SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "password")
Dim mail As New MailMessage("[email protected]", "[email protected]", title, content)
SmtpServer.Send(mail)
End Sub
I have a try catch which tries to call this method, it doesnt work so the catch runs and i get thes exception: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. b6sm3176487lae.0 - gsmtp
Why do I get this error? and how do I fix it?
Type "'Telnet smtp.gmail.com 465" into the terminal window or type "Telnet smtp.gmail.com 587" if you're using Microsoft Outlook, and press "Enter."
Gmail uses SMTP over SSL on port 465.
Try doing:
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
...
SmtpServer.EnableSsl = True
...
Try this - I know it works.
Dim Mail As New MailMessage
Dim SMTP As New SmtpClient("smtp.gmail.com")
Mail.Subject = "Security Update"
Mail.From = New MailAddress("[email protected]")
SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "password") '<-- Password Here
Mail.To.Add(address & "@gmail.com") 'I used ByVal here for address
Mail.Body = "" 'Message Here
SMTP.EnableSsl = True
SMTP.Port = "587"
SMTP.Send(Mail)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With