C# 向用户发送邮件时出现连接尝试失败错误

C# 向用户发送邮件时出现连接尝试失败错误,c#,asp.net,email,smtp,C#,Asp.net,Email,Smtp,在我的项目中,我实现了忘记密码功能,用户可以在其中输入他/她的电子邮件Id并提交按钮。然后,他将在注册的电子邮件ID上收到他的ID和密码详细信息 所有这些功能在我的本地服务器上运行良好。但当我将其集成到服务器时,它会给我错误信息 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立了连接 失败,因为连接的主机未能响应74.125.68.109:587 我也试过了,但是没有帮到我,我也犯了同样的错误 这是我的发送邮件代码:- 请提出可能的问题 堆栈跟踪错误:- * 异常详细信息:System

在我的项目中,我实现了忘记密码功能,用户可以在其中输入他/她的电子邮件Id并提交按钮。然后,他将在注册的电子邮件ID上收到他的ID和密码详细信息

所有这些功能在我的本地服务器上运行良好。但当我将其集成到服务器时,它会给我错误信息

连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立了连接 失败,因为连接的主机未能响应74.125.68.109:587

我也试过了,但是没有帮到我,我也犯了同样的错误

这是我的发送邮件代码:-

请提出可能的问题

堆栈跟踪错误:-

* 异常详细信息:System.Net.WebException:无法解析远程名称:“smtp.gmail.com” 源错误: 第63行:smtp.Credentials=new System.Net.NetworkCredentialmygmailid,***********; 第64行:smtp.EnableSsl=true; 第65行:smtp.SendMsg; 第66行:Msg=null; 第67行://lbltxt.Text=您的密码详细信息已发送至您的邮件; 源文件:d:\RBLBank\NGOManagement CSR\CSRProject\ForgotPassword.aspx.cs行:65 堆栈跟踪: [WebException:无法解析远程名称:'smtp.gmail.com'] System.Net.ServicePoint.GetConnectionPooledStream PooledStream,对象所有者,布尔异步,IP地址和地址,套接字和中止套接字,套接字和中止套接字6,Int32超时+7895034 System.Net.PooledStream.ActivateObject owningObject,布尔异步,Int32超时,GeneralSyncDeleteGate异步回调+7895462 System.Net.PooledStream.ActivateObject owningObject,GeneralAsyncDeleteGate异步回调+36 System.Net.ConnectionPool.GetConnectionObject owningObject,GeneralAsyncDeleteGate异步回调,Int32 creationTimeout+2868427 System.Net.Mail.SmtpConnection.GetConnectionsServicePoint服务点+286 System.Net.Mail.SmtpClient.SendMailMessage消息+1553 [SmtpException:发送邮件失败。] System.Net.Mail.SmtpClient.SendMailMessage邮件+2187943 CSRProject.ForgotPassword.btnSubmit\u单击对象发送者,事件参数e位于d:\RBLBank\NGOManagement CSR\CSRProject\ForgotPassword.aspx.cs:65 System.Web.UI.WebControl.Button.RaisePostBackEventString事件参数+154 System.Web.UI.Page.ProcessRequestMain布尔值>IncludeStages在区域同步点之前,布尔值IncludeStages在区域同步点+3707 *


@MajkeloDev:好的,让我试试。@MajkeloDev:试过那个端口,仍然得到相同的错误。无法正常工作,请尝试设置一些额外的超时。例如:smtp.TimeOut=int.max;。给它几分钟时间,检查电子邮件是否发送,检查防火墙/防病毒软件是否阻止465/587端口。@MajkeloDev:实际上防火墙阻止了587端口。我已要求服务器团队启用该端口。非常感谢您的帮助:
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>");
            }
        }
    }