簡體   English   中英

發送忘記密碼到電子郵件 Asp.net 代碼錯誤

[英]Send forget password to email Asp.net code error

我正在嘗試編寫代碼以通過電子郵件發送忘記的密碼,因此當用戶單擊“忘記密碼”按鈕時,應該將密碼發送到他們的電子郵件......但它會出現此錯誤

“/”應用程序中的服務器錯誤。 SMTP 服務器需要安全連接或客戶端未通過身份驗證。 服務器響應為:5.5.1 需要身份驗證。 在描述中了解更多信息:在執行當前 Web 請求期間發生未處理的異常。 請查看堆棧跟蹤以獲取有關錯誤及其在代碼中的來源的更多信息。

異常詳細信息:System.Net.Mail.SmtpException:SMTP 服務器需要安全連接或客戶端未通過身份驗證。 服務器響應為:5.5.1 需要身份驗證。 了解更多信息

源錯誤:

第 50 行:smtp.Send(ms);

源代碼在這里:

       protected void Buttonpsw_Click(object sender, EventArgs e)
         {
        string mainconn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
        SqlConnection con = new SqlConnection(mainconn);
        string sqlquery = "select Email,Password1 from [dbo].[Users1] where Email =@Email";
        SqlCommand sqlcommand = new SqlCommand(sqlquery, con);
        sqlcommand.Parameters.AddWithValue("@Email",Textemail.Text);
        con.Open();
        SqlDataReader sdr = sqlcommand.ExecuteReader();
        if (sdr.Read())
        {

            string username = sdr["Email"].ToString();
            string Password = sdr["Password1"].ToString();
            MailMessage ms = new MailMessage("roqaia.alrfou@gmail.com",Textemail.Text);
            ms.Subject = "Your password!";
            ms.Body = string.Format("Hello : <h1>{0}</h1> is your Email ID <br/> Your Password is <h1>{1}</h1>",username,Password);
            ms.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            NetworkCredential nc = new NetworkCredential();
            nc.UserName = "roqaia.alrfou@gmail.com";
            nc.Password = "133";
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = nc;
            smtp.Port = 587;
            smtp.Send(ms);
            Labelmsg.Text = "Your Password has been sent to" + Textemail.Text;
            Labelmsg.ForeColor = Color.Green;


        }
        else
        {
            Labelmsg.Text = Textemail.Text+" This Email ID isn't Exist! Please sign up";
            Labelmsg.ForeColor = Color.Red;

        }

Web 配置中的連接字符串具有以下代碼:( Tracking_System 是我的數據庫名稱

    <connectionStrings>
        <add name="dbconnection"
             connectionString="server= USER-PC\SQL;Data 
   Source=localhost;Initial Catalog=Tracking_System;
   Integrated Security=True;Pooling=False
   ; Trusted_Connection=True;"
         providerName="System.data.sqlclient" />
</connectionStrings>

我試圖在命令提示符下 ping smtp 它給出了這個:

C:\\WINDOWS\\system32>ping smtp.google.com Ping 請求找不到主機 smtp.google.com。 請檢查名稱並重試。

C:\\WINDOWS\\system32>ping smtp.gmail.com

ping gmail-smtp-msa.l.google.com [64.233.184.108] 有 32 個字節的數據: 來自 64.233.184.108 的回復:bytes=32 時間=85ms TTL=37 來自 64.233.184.108 的回復時間=9 bytes33ms TTL=37 來自 64.233.184.108 的回復:bytes=32 時間=86ms TTL=37 來自 64.233.184.108 的回復:bytes=32 時間=85ms TTL=37

64.233.184.108 的 Ping 統計數據:數據包:發送 = 4,接收 = 4,丟失 = 0(丟失 0%),以毫秒為單位的近似往返時間:最小值 = 85 毫秒,最大值 = 91 毫秒,平均值 = 86 毫秒

當您嘗試從不同的時區或 IP 地址計算機登錄時,通常會發生這種情況。 您的生產服務器和您使用的郵件 ID 位於不同的時區。 選擇以下任一解決方案:

1) 通過遠程訪問登錄到生產服務器,並使用您的憑據登錄一次 gmail。 他們將要求確認,確認並注銷。

或 2) 將 gmail 登錄到您的本地計算機,點擊此鏈接並選擇查看此活動並采取適當的措施。

我通過此鏈接找到了Gmail 錯誤:SMTP 服務器需要安全連接或客戶端未通過身份驗證。 服務器響應為:5.5.1 Authentication Required

問題是我的郵箱密碼錯誤, nc.Password = "133"; 我認為正確的密碼來自數據庫而不是我電子郵件的真實密碼。 所以上面的代碼是 100% 正確的。希望有人需要它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM