1. 程式人生 > >QQ郵箱驗證碼

QQ郵箱驗證碼

郵件 clas else using tcs network label 。。 郵件內容

人的記憶有時候跟魚一樣,只有七秒鐘,短暫的時間!

.NET Web窗體實現忘記密碼,使用QQ郵箱驗證修改

一、首先設置一下發送個人或企業發送的郵箱

二、登錄郵箱進行設置,如圖:

技術分享圖片

技術分享圖片

技術分享圖片

三、關閉郵箱

四、開始寫代碼。。。

1.前端就簡單的設計下

技術分享圖片

2.後臺首先引用命名空間

using System.Net;
using System.Net.Mail;

/// <summary>
/// 發送驗證碼
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
//已發送提示
this.Label1.Text = "*驗證碼已發送至您的郵箱,請註意查收!";
//隨機生成驗證碼
int num;
string str = string.Empty;
Random rm = new Random();
for(int i=0;i<6;i++)
{
num = Convert.ToInt32(rm.NextDouble()*10);
str += num;
}
Session["Rom"] = str;
string content = "***科技提醒您:您正在使用去共創郵箱安全驗證服務,您本次操作的驗證碼是:" + str;
//收件人郵箱,郵箱標題,郵箱內容
SendEmail1("[email protected]", "【小張科技】後臺登錄修改用戶信息提示", content);
}

/// <summary>
///發送郵箱驗證碼
/// </summary>
/// <param name="mailTo">收件人</param>
/// <param name="mailSubject">標題</param>
/// <param name="mailContent">內容</param>
///
public static void SendEmail1(string mailTo, string mailSubject, string mailContent)
{
SmtpClient mailClient = new SmtpClient("smtp.qq.com");
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
//Credentials登陸SMTP服務器的身份驗證.
mailClient.Credentials = new NetworkCredential("[email protected]", "suzgotcsfwbpbbec");//郵箱,
MailMessage message = new MailMessage(new MailAddress("[email protected]"), new MailAddress(mailTo));//發件人,收件人
message.IsBodyHtml = true;
message.Body = mailContent;//郵件內容
message.Subject = mailSubject;//郵件主題
mailClient.Send(message); // 發送郵件
}

/// <summary>
///登錄
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button2_Click(object sender, EventArgs e)
{
if (TextBox1.Text.Trim() == Session["Rom"].ToString())
{
Response.Write("<script>alert(\"驗證成功!\");</script>");
this.Label1.Text = "";
}
else
{
Response.Write("<script>alert(\"驗證失敗!\");</script>");
this.Label1.Text = "*驗證碼錯誤。請重新輸入!";
}
}

就這樣結束,可以運行啦。 歡迎關註,共同學習!

QQ郵箱驗證碼