How to test this server code?

Failure sending mail. unable to connect to remote server.(In Asp.net)?

  • I am trying to send mails using gmail Smtp server from my asp.net application.But i am getting error as below. 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 202.86.4.47:587 at System.Net.Sockets.Socket.DoConnect(EndP… endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnec… remoteEP) at System.Net.ServicePoint.ConnectSocketInt… connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) Here is the Code: string from = "[email protected]"; string to = "[email protected]" ; System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(to); mail.From = new MailAddress(from, "One Ghost" , System.Text.Encoding.UTF8); mail.Subject = "This is a test mail" ; mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.Body = "This is Email Body Text"; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true ; mail.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = false; //Add the Creddentials- use your own email id and password client.Credentials = new System.Net.NetworkCredential(from, "mygmailpassword"); client.Port = 587; // Gmail works on this port client.Host = "smtp.gmail.com"; client.EnableSsl = true; //Gmail works on Server Secured Layer try { client.Send(mail); } catch (Exception ex) { Exception ex2 = ex; string errorMessage = string.Empty; while (ex2 != null) { errorMessage += ex2.ToString(); ex2 = ex2.InnerException; } HttpContext.Current.Response.Write(error… ); } // end try

  • Answer:

    Gmails SSL server is port 465. 587 is non SSL Edit: See if any of this information is helpful. http://techblissonline.com/gmail-smtp/

satish k at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.