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

时间:2015-03-31 07:11:53

标签: c# asp.net email smtp

在我的项目中,我实施了Forgot password功能,用户输入他/她的Email-Id ID并提交按钮。然后,他将在已注册的电子邮件ID上收到他的ID和密码详细信息。

这一切功能在我的本地服务器上正常运行。但是当我将它集成到服务器时,它会给我带来错误

  

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

我也试过这个link,但它没有帮助我,并且得到了同样的错误。

这是我的Send Mail代码: -

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>");
            }
        }
    }

请提出可能存在的问题。

STACK TRACE ERROR: -

  

*   异常详细信息:System.Net.WebException:无法解析远程名称:'smtp.gmail.com'   来源错误:   第63行:smtp.Credentials = new System.Net.NetworkCredential(“mygmailid”,“************”);   第64行:smtp.EnableSsl = true;   第65行:smtp.Send(Msg);   第66行:Msg = null;   第67行://lbltxt.Text =“您的密码详细信息已发送到您的邮箱”;   源文件:d:\ RBLBank \ NGOManagement-CSR \ CSRProject \ ForgotPassword.aspx.cs行:65   堆栈跟踪:   [WebException:无法解析远程名称:'smtp.gmail.com']      System.Net.ServicePoint.GetConnection(PooledStream PooledStream,Object owner,Boolean async,IPAddress&amp; address,Socket&amp; abortSocket,Socket&amp; 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:发送邮件失败。]      System.Net.Mail.SmtpClient.Send(MailMessage message)+2187943      CSRProject.ForgotPassword.btnSubmit_Click(Object sender,EventArgs e)在d:\ RBLBank \ NGOManagement-CSR \ CSRProject \ ForgotPassword.aspx.cs:65      System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+154      System.Web.UI.Page.ProcessRequestMain(Boolean&gt; includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+3707   *

0 个答案:

没有答案