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
Note i tried with 465 and 25 as ports,still same problem.
1.Port 465 - error as "Failure sending mail." and InnerException as "Unable to read data from the transport connection: net_io_connectionclosed."
2.Port 25 - error as "Failure sending mail." and InnerException as "Unable to connect to the remote server"
And one more thing i tried with another gmail account with enabled 2 step versification and with app password working fine, i mean from my another account can send mail.
try to use port 465 port or 25 port instead of 587,hope this will solve your issue if further details you want then please refer to this link
https://kinsta.com/blog/gmail-smtp-server/
Related
Ok, so, I have this code, that creates a TCPListener and a TCPClient, the code work, just not for me, my server is in my own home, in another machine, so I passed the server software to that and I tried to connect using my client, the client sends the request, the server picks it up, analyses it, and then throw it back, but, when it throws it back, the IP is the same so it's redirected to the server again, and the client never gets a response, This only happen in TCP tho, UDP do the job, but I need TCP to work
Server Code:
Dim Listener As New TcpListener(IPAddress.Any, 8123)
Dim Client As New TcpClient
Dim Message As String = ""
Dim games As New List(Of GameClass)
Dim queue As New Dictionary(Of String, IPEndPoint)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim ListenerThread As New Thread(New ThreadStart(AddressOf Listening))
ListenerThread.Start()
End Sub
Private Sub Listening()
Listener.Start()
End Sub
Sub Send(msg As String, ip As IPEndPoint)
Try
Client = New TcpClient(ip)
ListBox1.Items.Add("Sending: " & msg & " to: " & ip.Address.ToString)
'Declare the Client as an IP Address.
'Must be in the Correct form. eg. 000.0.0.0
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(msg)
Writer.Flush()
'Write the Message in the stream
Catch ex As Exception
Try
Client = New TcpClient(New IPEndPoint(IPAddress.Parse("127.0.0.1"), ip.Port))
ListBox1.Items.Add("Sending: " & msg & " to: " & ip.Address.ToString)
'Declare the Client as an IP Address.
'Must be in the Correct form. eg. 000.0.0.0
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(msg)
Writer.Flush()
Catch ex1 As Exception
End Try
End Try
End Sub
Sub Send(msg As String, index As Integer, ip As IPEndPoint)
Try
For Each item In games(index).IPAddresses
If item.Value.Address.ToString = ip.Address.ToString Then
Else
Client = New TcpClient(ip)
'Declare the Client as an IP Address.
'Must be in the Correct form. eg. 000.0.0.0
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(msg)
Writer.Flush()
End If
Next
Catch ex As Exception
Try
Client = New TcpClient(New IPEndPoint(IPAddress.Parse("127.0.0.1"), ip.Port))
ListBox1.Items.Add("Sending: " & msg & " to: " & ip.Address.ToString)
'Declare the Client as an IP Address.
'Must be in the Correct form. eg. 000.0.0.0
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(msg)
Writer.Flush()
Catch ex1 As Exception
End Try
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Listener.Pending = True Then
Message = ""
Client = Listener.AcceptTcpClient()
Dim Reader As New StreamReader(Client.GetStream())
While Reader.Peek > -1
Message = Message + Convert.ToChar(Reader.Read()).ToString
End While
Parse(Message, Client.Client.RemoteEndPoint)
End If
End Sub
Any suggestions, please, If it's duplicate, please just link to another post, I don't have even the words to ask this on google
Can you break this down into 2 sections? Client Send & Recieve code and server send & receive code?
First off no computer has the same IP. Your client IP machine can have the IP address of 192.168.1.125 and your server machine could have 192.168.1.56. 2 machines connected to a network can never have a conflicting IP address.
I have successfully coded my own client/server application that works on the internet and the intranet (home network). I can help you.
But please break your code down into 2 sections of Client Side & Server Side.
I'm trying to send a message using EWS Managed API, and I need to confirm message was sent and register some info (ex. the date & time it was sent). However, I get an exception as shown below. My question is: how can I retrieve the EmailMessage object for the sent message, after it was sent?
Thank you very much!
Private Sub NovaMensagemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NovaMensagemToolStripMenuItem.Click
Dim em As New EmailMessage(serviceClient.Service)
em.Subject = "Test"
em.Body = "This is a test."
em.ToRecipients.Add("mytestmail#test.com")
em.SendAndSaveCopy(WellKnownFolderName.SentItems)
em.Load() 'Exception: System.InvalidOperationException: This operation can't be performed because this service object doesn't have an Id.
MsgBox(em.DateTimeSent)
End Sub
Apparently, all it takes is to save a draft before sending:
Private Sub NovaMensagemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NovaMensagemToolStripMenuItem.Click
Dim em As New EmailMessage(serviceClient.Service)
em.Subject = "Test"
em.Body = "This is a test."
em.ToRecipients.Add("mytestmail#test.com")
em.Save(WellKnownFolderName.Drafts) '<--- added this
em.SendAndSaveCopy(WellKnownFolderName.SentItems)
em.Load() 'no exception now
MsgBox(em.DateTimeSent)
End Sub
i want to send an email with my gmail account but i have this error and the email doas'nt sent !
http://up.dev-point.com/uploads1/a75d55e308e91.png
My code is :
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 587)
SmtpServer.Credentials = New Net.NetworkCredential("ihab#gmail.com", "pass")
Dim mail As New MailMessage("ihab#gmail.com", "ihab#gmail.com", "New", "txt")
SmtpServer.Send(mail)
End Sub
Please see this case, I think you need to make sure SSL is enabled and possibly modify account settings for smtp access.
Sending email through Gmail SMTP server with C#
If you need assistance converting the C# code to vb.net let me know
So, I'm trying to send an email using the code below, and I get this error:
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated.
I've already allowed unsecure applications to send me emails and turned off my 2-Step Verification on my gmail, and of course I replaced Net.NetworkCredential("myvalidemail#gmail.com", "mypassword") with my real email and password, but I still get that error.
I am running the program through VB debug, but that shouldn't matter.
Private Sub SendBtn_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SendBtn.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.UseDefaultCredentials = False
SmtpServer.Credentials = New _
Net.NetworkCredential("myvalidemail#gmail.com", "mypassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("myvalidemail#gmail.com")
mail.To.Add("myvalidemail#gmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
mail.Priority = MailPriority.High
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
The exception says that SMTP server requires a secure connection. Try enabling the SSL
SmtpServer.EnableSsl = true;
"client was not authenticated"
Just a thought: do you use Google Two Factor Authorization?
I am trying to send SMTP email from my vb.net form application. When applying this code, I get the error below. What am I doing wrong?
Code:
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("myemail#gmail.com", "mypassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("myemail#gmail.com")
mail.To.Add("sendto#hotmail.co.uk")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Error:
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
Check if the login and password are correct;
Use SmtpServer.EnableSsl = true;
Gmail has disabled access using credentials (user and password) by default, you need go to this page: https://www.google.com/settings/security/lesssecureapps and "Enable Less Secure Apps", this means: "Enable login by apps using user and password". More details here: https://support.google.com/accounts/answer/6010255
See if this helps; Add
SmtpServer.EnableSSL= true
I know this was last year but I thought I should publish the answer as five minutes ago I had the same issue.
Basically your log in credentials are incorrect and need changing.
Also thanks for the previous answer has that piece of code allows me to send emails over SSL encryption (I Hope LOL).