人的记忆有时候跟鱼一样,只有七秒钟,短暂的时间!
.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("xxx@qq.com", "【小张科技】后台登录修改用户信息提示", 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("xxx@qq.com", "suzgotcsfwbpbbec");//邮箱,
MailMessage message = new MailMessage(new MailAddress("xxx@qq.com"), 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 = "*验证码错误。请重新输入!";
}
}
就这样结束,可以运行啦。 欢迎关注,共同学习!