Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that a user can enter their email address and click the submit button. Then the user will get an email with their password in it. When I test the form and enter in an email address and click submit the form takes a while to go through and then it times out. The error is:

The operation has timed out. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.Mail.SmtpException: The operation has timed out.

The Trace is:

Stack Trace:


[SmtpException: The operation has timed out.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1798
   ForgotPassword.btnPass_Click(Object sender, EventArgs e) in C:\Users\khopkins\Documents\Visual Studio 2010\Projects\SACSCOCLogin1.1\SACSCOCLogin1.1\ForgotPassword.aspx.cs:67
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9552874
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724


The Code is:

C#
protected void btnPass_Click(object sender, EventArgs e)
    {
        //Create Connection String And SQL Statement
        string strConnection = ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString;
        string strSelect = "select INST_ID, EmailAddress, Password from Tablepass where EmailAddress ='" + TextBoxEA.Text.Trim() + "'";

        SqlConnection connection = new SqlConnection(strConnection);
        SqlCommand command = new SqlCommand();
        command.Connection = connection;
        command.CommandType = CommandType.Text;
        command.CommandText = strSelect;

        SqlParameter email = new SqlParameter("@EmailAddress", TextBoxEA.Text.Trim());
        email.Value = TextBoxEA.Text.Trim().ToString();
        command.Parameters.Add(email);

        //Create Dataset to store results and DataAdapter to fill Dataset 
        DataSet dsPwd = new DataSet();
        connection.Open();
        SqlDataAdapter dAdapter = new SqlDataAdapter(command);
        dAdapter.Fill(dsPwd);
        connection.Close();
        if (dsPwd.Tables[0].Rows.Count > 0)
        {
            MailMessage loginInfo = new MailMessage();
            loginInfo.To.Add(TextBoxEA.Text.ToString());
            loginInfo.From = new MailAddress("Admin@fastfix.com", "Southern Association of Colleges and Schools Commission on Colleges");
            loginInfo.Subject = "Forgot Password Information";

            loginInfo.Body = "EmailAddress: " + dsPwd.Tables[0].Rows[0]["EmailAddress"] + "<br /><br />Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "<br /><br />";
            loginInfo.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient("mail.fastfix.com");
            smtp.Host = "mail.sacscoc.org";
            smtp.Port = 80;
            smtp.EnableSsl = true;
            smtp.Credentials = new System.Net.NetworkCredential("@EamilAddress", "YourEmailPassword");
            smtp.Send(loginInfo);
            lblMessage.Text = "Password is sent to your email<a href='Login.aspx'>Login</a>";

            try
            {
                smtp.Send(loginInfo);
            }
            catch (Exception ex)
            {

                lblMessage.Text = "Oops, Something Went Wrong When We Tried to Send The Email";
                return;
            }

        }
        else
        {
            lblMessage.Text = "Email Address Not Registered";
        }

    }

    
}


What did I do wrong to get this error? Is there a way to fix it?
Posted
Comments
ZurdoDev 19-Nov-13 12:27pm    
You need to get with your SMTP provider and make sure you have all the correct settings.

C#
smtp.Port = 80;


Usually SMTP protocol listens on port 25; port 80 is for HTTP protocol.
Can you try to set
C#
smtp.Port = 25;

and see if it changes anything?
 
Share this answer
 
Comments
Computer Wiz99 19-Nov-13 13:15pm    
phil.o, Thanks for the info but I did that already.
phil.o 19-Nov-13 13:47pm    
OK; but be sure port 80 is a mistake
Computer Wiz99 19-Nov-13 14:13pm    
Yeah, I have tried both ports. The both time out. I am looking over the config on the mail server.
I did sole this my self. I had to increase the timeout on the smtp and give permission to the server for my other servers.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900