Click here to Skip to main content
14,389,400 members
Rate this:
Please Sign up or sign in to vote.
Dim clie As New SmtpClient("smtp.gmail.com", 587)
clie.Credentials = New Net.NetworkCredential(txtemail.Text, txtpass.Text)

Dim fromwho As String = "abcdef@noreply.com"
Dim towho As String = txtto.Text
Dim subject As String = txtsubject.Text
Dim body As String = txtBody.Text
clie.EnableSsl = True
clie.Send(fromwho, towho, subject, body)



I have this code above.. and it has error like this :

Exception:Thrown: "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" (System.Net.Sockets.SocketException)
A System.Net.Sockets.SocketException was thrown: "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"
Time: 9/23/2015 9:17:43 AM
Thread:<No Name>[1056]




Beofre it was working but now i dont know the problem.
Posted
Comments
[no name] 23-Sep-15 0:35am
   
I guess the port number is creating issue. Sometimes the port you are configuring is having issues. Try with port number 465.You can use default port 25 or enable there ports on firewall.
NekoNao 23-Sep-15 5:48am
   
tried port 25 but samee issue.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

Try like this.

Dim Smtp_Server As New SmtpClient
          Dim e_mail As New MailMessage()
          Smtp_Server.UseDefaultCredentials = False
          Smtp_Server.Credentials = New Net.NetworkCredential("username@gmail.com", "password")
          Smtp_Server.Port = 587
          Smtp_Server.EnableSsl = True
          Smtp_Server.Host = "smtp.gmail.com"

          e_mail = New MailMessage()
          e_mail.From = New MailAddress(txtFrom.Text)
          e_mail.To.Add(txtTo.Text)
          e_mail.Subject = "Email Sending"
          e_mail.IsBodyHtml = False
          e_mail.Body = txtMessage.Text
          Smtp_Server.Send(e_mail)
          MsgBox("Mail Sent")


If still you are facing the same issue let me know.

Thanks,
Sisir Patro
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100