In my project, I have implemented a Forgot password
functionality where users enters his/her Email-Id ID and submits the button. Then he will receive his ID and password details on the Registered email id.
This all functionality is working fine on my local server. But when I integrated this to server, it gives me error as
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 74.125.68.109:587
I also tried this link but it did not helped me out and was getting the same error.
Here is my Send Mail
Code:-
protected void btnSubmit_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT username,password FROM tbl_User Where email= '" + txtEmail.Text.Trim() + "'", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
conn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail.Text);
// Recipient e-mail address.
Msg.To.Add(txtEmail.Text);
Msg.Subject = "Password Details";
Msg.Body = "Hi, <br/>Your login details are<br/><br/>Your Username is: " + ds.Tables[0].Rows[0]["username"] + "<br/><br/>Your Password is: " + Decrypt(ds.Tables[0].Rows[0]["password"].ToString()) + "<br/><br/>";
Msg.IsBodyHtml = true;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("mygmailid", "**********");
smtp.EnableSsl = true;
smtp.Send(Msg);
Msg = null;
//lbltxt.Text = "Your Password Details Sent to your mail";
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Your Password Details Sent to your mail');window.location ='Login.aspx';", true);
// Clear the textbox valuess
txtEmail.Text = "";
}
else
{
Response.Write("<script>alert('Email Id you entered does not exist');</script>");
}
}
}
Please suggest what might be the issue.
STACK TRACE ERROR:-
* Exception Details: System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com' Source Error: Line 63: smtp.Credentials = new System.Net.NetworkCredential("mygmailid", "************"); Line 64: smtp.EnableSsl = true; Line 65: smtp.Send(Msg); Line 66: Msg = null; Line 67: //lbltxt.Text = "Your Password Details Sent to your mail"; Source File: d:\RBLBank\NGOManagement-CSR\CSRProject\ForgotPassword.aspx.cs Line: 65 Stack Trace: [WebException: The remote name could not be resolved: 'smtp.gmail.com'] System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +7895034 System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +7895462 System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +36 System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +2868427 System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +286 System.Net.Mail.SmtpClient.Send(MailMessage message) +1553 [SmtpException: Failure sending mail.] System.Net.Mail.SmtpClient.Send(MailMessage message) +2187943 CSRProject.ForgotPassword.btnSubmit_Click(Object sender, EventArgs e) in d:\RBLBank\NGOManagement-CSR\CSRProject\ForgotPassword.aspx.cs:65 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154 System.Web.UI.Page.ProcessRequestMain(Boolean >includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707 *