0
Shared Sub sendMail(ByVal title As String, ByVal content As String)
    Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
    SmtpServer.EnableSsl = True
    SmtpServer.Credentials = New Net.NetworkCredential(username, password)
    Dim mail As New MailMessage(username, username, title, content)
    SmtpServer.Send(mail)
End Sub

I got the result of

System.Net.Mail.SmtpException: 'Failure sending mail.'
IOException: Unable to read data from the transport connection: net_io_connectionclosed.

What did I do wrong? Should I enable IMAP first at google?

My code is based on How do I send a gmail email in vb.net?

If I use port 587 instead of 465 I got

System.Net.Mail.SmtpException: 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at'

Using port 25 yield

SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.200.109:25

Using 465 yield the original error

user4951
  • 29,779
  • 47
  • 157
  • 270
  • See this it can be helpful [How do I send a gmail email in vb.net?](https://stackoverflow.com/questions/18153542/how-do-i-send-a-gmail-email-in-vb-net) – Mohammad Tavakoli Oct 21 '17 at 17:00
  • Ah I found it again. I forget to mention, my code is based on that code. As you see I already add smtpserver.enablessl= true. Still doesn't work – user4951 Oct 21 '17 at 17:10
  • Did you try different ports? I think Google uses either 25, 465 or 587. – Visual Vincent Oct 21 '17 at 17:15
  • The answer says I got to use 465. Let me try the others – user4951 Oct 21 '17 at 17:27
  • That answer is dated four years back, things can change ;). -- However as none of them worked I did a little more digging... It seems you might have to [**turn on a setting called "Allow less secure apps"**](https://stackoverflow.com/a/29465275) on your Google account for it to work sending emails with. The problem could be that your application doesn't support the required security protocols by default, in which case you might want to try [**fiddling with them first**](https://stackoverflow.com/a/29221917). – Visual Vincent Oct 21 '17 at 18:18

0 Answers0