C# QQ邮箱注册,以及数秒
2021-02-21 02:21
一、
这是前台需要的东西
//这个是存放时间
//这个是用以判断验证码过期
这是js代码部分
var endDate = new Date(date);
if (now var leftTime = endDate.getTime() - now.getTime();
var leftsecond = parseInt(leftTime / 1000);
//ar day1=parseInt(leftsecond/(24*60*60*6));
var day1 = Math.floor(leftsecond / (60 * 60 * 24));
var hour = Math.floor((leftsecond - day1 * 24 * 60 * 60) / 3600);
var minute = Math.floor((leftsecond - day1 * 24 * 60 * 60 - hour * 3600) / 60);
var second = Math.floor(leftsecond - day1 * 24 * 60 * 60 - hour * 3600 - minute * 60);
//document.getElementById("TimerH").innerHTML = day1 * 24 + hour;
//document.getElementById("TimerM").innerHTML = minute;
document.getElementById("miao").innerHTML = second;
} else {
document.getElementById("miao").innerHTML = "";//当时间过期变成空
var ts = $("#").val("Failure");//这个是用以判断验证码过期的隐藏控件的值
}
}
window.setInterval(function () { ShowCountDown(); }, interval);
这下面是后台代码
protected void Button2_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage(); //实例化一个email类
string email = Textemail.Text.Trim();
if(email!="")
{
msg.To.Add(email);
msg.CC.Add("1395789551@qq.com"); //抄送人地址
msg.From = new MailAddress("1395789551@qq.com", "崔小强"); //发送人地址
msg.Subject = "验证码"; //邮件标题
msg.SubjectEncoding = Encoding.UTF8; // 字符格式
msg.Body =suiji(); //邮件内容 这里调的一个方法返回一个四位验证码
Session["yan"] = msg.Body; //把邮件内容存到Session中
msg.BodyEncoding = Encoding.UTF8; //设置邮件内容的编码格式
SmtpClient client = new SmtpClient(); //用来传输简单邮件的smtp协议
client.Host = "smtp.qq.com"; //QQ的IP地址
client.Port = 587; //事务的端口
client.EnableSsl = true; //加密链接
client.Credentials = new NetworkCredential("1395789551@qq.com", "rrcntqllbhahjgcd"); //用于验证发件人的身份凭据
client.Send(msg); //将邮件发送到smtp服务器,传递
DateTime timed = System.DateTime.Now;
DateTime times = timed.AddMinutes(1);//给当前时间加上一分钟
hfTimer.Value = times.ToString("yyyy/MM/dd HH:mm:ss");//给前台的隐藏控件赋值
time.Value = "";//给用于验证验证码过期的控件赋空
}
}