Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 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

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

Scheduled Pinned Locked Moved C#
csharpcomsysadmindata-structuresdebugging
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bigz_1000
    wrote on last edited by
    #1

    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

    M J 2 Replies Last reply
    0
    • B bigz_1000

      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

      M Offline
      M Offline
      Mehdi Gholam
      wrote on last edited by
      #2

      Gmail requires EnableSsl = true

      Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist

      B 1 Reply Last reply
      0
      • M Mehdi Gholam

        Gmail requires EnableSsl = true

        Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist

        B Offline
        B Offline
        bigz_1000
        wrote on last edited by
        #3

        I set EnableSsl = true but I have same exception

        D 1 Reply Last reply
        0
        • B bigz_1000

          I set EnableSsl = true but I have same exception

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          B 1 Reply Last reply
          0
          • B bigz_1000

            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

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            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.

            B 1 Reply Last reply
            0
            • D Dave Kreskowiak

              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

              B Offline
              B Offline
              bigz_1000
              wrote on last edited by
              #6

              yes ... Thanks

              1 Reply Last reply
              0
              • J jschell

                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.

                B Offline
                B Offline
                bigz_1000
                wrote on last edited by
                #7

                Thanks for this :)

                M 1 Reply Last reply
                0
                • B bigz_1000

                  Thanks for this :)

                  M Offline
                  M Offline
                  Michael J Eber
                  wrote on last edited by
                  #8

                  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;

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups