Hi All,
I am using Gmail setting for sending mail, i got an error like "Failure sending mail." and InnerException as "Unable to read data from the transport connection: net_io_connectionclosed."
My project frame work is .Net 4.8
Programming Language vb
OS is Windows 11
Anything need to change in Gmail account setting ?
What I have tried:
Imports System.Net
Imports System.Net.Mail
Public Class Form1
Public Shared Function ServerCertificateValidationCallback(ByVal sender As Object, ByVal cert As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As Net.Security.SslPolicyErrors) As Boolean
Return True
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
Dim Mail As New System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient
Mail.From = New MailAddress("aravind@gmail.com", "Aravind")
Mail.To.Add("aravind1@gmail.com")
Mail.IsBodyHtml = True
Mail.Subject = "Hai Testing Mail"
smtp = New SmtpClient("smtp.gmail.com", "587")
smtp.EnableSsl = True
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential("aravind@gmail.com", "xxxxxxxxxxx")
Dim userstate As Object = Mail
System.Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf ServerCertificateValidationCallback
smtp.Send(Mail)
Catch ex As Exception
MessageBox.Show(ex.InnerException.ToString)
MessageBox.Show(ex.Message.ToString)
End Try
End Sub
End Class
Same code with another gmail account working fine,
Note: i created app password from security tab, one account working another cant, both i enabled 2 step verification.