Email Sender :the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
-
Hi there, I have another problem in my code, this is my code :
private void SendEmail(MailMessage message, MailAddress from)
{SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); smtpClient.EnableSsl = false; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential("someone@gmail.com", "password"); try { smtpClient.Send(message); } catch (Exception ex) { throw new Exception(ex.Message); } finally { message.Dispose(); } }
and now I have following exception in line "smtpClient.Send(message)" : System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.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 209.85.143.108:587 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at EmailSender.EmailSenderForm.SendEmail(MailMessage message, MailAddress from) in is i
-
Hi there, I have another problem in my code, this is my code :
private void SendEmail(MailMessage message, MailAddress from)
{SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); smtpClient.EnableSsl = false; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential("someone@gmail.com", "password"); try { smtpClient.Send(message); } catch (Exception ex) { throw new Exception(ex.Message); } finally { message.Dispose(); } }
and now I have following exception in line "smtpClient.Send(message)" : System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.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 209.85.143.108:587 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at EmailSender.EmailSenderForm.SendEmail(MailMessage message, MailAddress from) in is i
Gmail requires
EnableSsl = true
Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist
-
Gmail requires
EnableSsl = true
Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist
-
I alreayd told you what the problem is. There's nothing wrong with your code. You've got a network problem that we cannot solve for you. Your errors are telling you that the gmail network isn't reachable. That means you've got one or more firewalls blocking traffic to either gmail, or blocking anything on port 587, or you're got much larger network issues to deal with. There is no code in the world that is going to get around that problem. You either have to have your network administrators fix this, or give up on getting this to work.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi there, I have another problem in my code, this is my code :
private void SendEmail(MailMessage message, MailAddress from)
{SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); smtpClient.EnableSsl = false; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential("someone@gmail.com", "password"); try { smtpClient.Send(message); } catch (Exception ex) { throw new Exception(ex.Message); } finally { message.Dispose(); } }
and now I have following exception in line "smtpClient.Send(message)" : System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.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 209.85.143.108:587 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at EmailSender.EmailSenderForm.SendEmail(MailMessage message, MailAddress from) in is i
Regarding the other post about connectivity. A simple test for connectivity is the following at the command line. telnet smtp.gmail.com 587 If the above succeeds you will get a cursor blinking waiting for you to type something (you don't need to type anything, you just need to have it waiting.) If it doesn't work then it will say something like "connecting..." for a while and then tell you that it timed out, of failed to connect or some other error. Notice that the above has nothing to do with C# or any other programming language. And until that work nothing you do in C# will make it work. And I will note that I tried the exact line above and it worked for me. So the host and port are correct.
-
I alreayd told you what the problem is. There's nothing wrong with your code. You've got a network problem that we cannot solve for you. Your errors are telling you that the gmail network isn't reachable. That means you've got one or more firewalls blocking traffic to either gmail, or blocking anything on port 587, or you're got much larger network issues to deal with. There is no code in the world that is going to get around that problem. You either have to have your network administrators fix this, or give up on getting this to work.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Regarding the other post about connectivity. A simple test for connectivity is the following at the command line. telnet smtp.gmail.com 587 If the above succeeds you will get a cursor blinking waiting for you to type something (you don't need to type anything, you just need to have it waiting.) If it doesn't work then it will say something like "connecting..." for a while and then tell you that it timed out, of failed to connect or some other error. Notice that the above has nothing to do with C# or any other programming language. And until that work nothing you do in C# will make it work. And I will note that I tried the exact line above and it worked for me. So the host and port are correct.
-
PING and TRACERTE can also help you in your issues as well. If you do a PING SMTP.GMAIL.COM and you get no resolve then you know it is a DNS error in your network. If you do a PING and you get a resolve but then timeout, you might have a firewall issue. A TRACERTE (not sure of utility name....sorry) will show you how far you go in connecting to the server. It may stop inside your network or you are getting to the firewall and to an external router but no further. In that case your router isn't forwarding it out to the internet.
Software Zen: delete this;