asp网站实现邮件的发送(注册为例)
来源:互联网 发布:父母从小偏心知乎 编辑:程序博客网 时间:2024/06/05 15:51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Net.Mail;
using System.Net;
public partial class register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string CheckCode()
{
int num;
char code;
string checkCode = string.Empty;
Random random = new Random();
for (int i = 0; i < 6; i++)//循环次数决定验证码的位数
{
num = random.Next();
if (num % 2 == 0)
{
code = (char)('0' + (char)(num % 10));
}
else
{
code = (char)('A' + (char)(num % 26));
}
checkCode += code.ToString();
}
//Response.Cookies.Add(new HttpCookie("CheckCode", checkCode));
return checkCode;
}
protected void mailBind()
{
string lianjie = "http://localhost:2486/MailActivationOperation/register.aspx?code="+CheckCode();
System.Net.Mail.MailMessage msg = new MailMessage();
msg.Body = "欢迎您来到CSDN注册激活,您的激活码是" + CheckCode() +"<br/>"+ "点击链接可完成注册"+"<br/>" + lianjie;
msg.From = new MailAddress("Leihaijiayuan@163.com"); //主机邮箱
//msg.Sender = new MailAddress("");
msg.To.Add(this.txtmail.Text);
msg.Subject = "CSDN注册激活";
msg.IsBodyHtml = true; //邮件内容默认是纯文本!如果指定html内容,需要使用isbodyHtml
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.163.com"; //主机邮箱类别
sc.Port = 25;
NetworkCredential nc = new NetworkCredential();
nc.UserName = "leihaijiayuan"; //主机邮箱名称
nc.Password = "*********"; //主机邮箱密码
sc.Credentials = nc;
sc.Send(msg);
Response.Write("<script>alert('邮件已发送至您的邮箱,请去您的邮箱获取动态验证码!')</script>");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.txtmail.Text != null&&this.txtkouling.Text=="")
{
mailBind();
}
else if (this.txtmail.Text != null && this.txtkouling.Text != null)
{
string scc=Request["code"].ToString();
if (this.txtkouling.Text == scc)
{
string str = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
using (SqlConnection sqlcnn = new SqlConnection(str))
{
using (SqlCommand sqlcmm = sqlcnn.CreateCommand())
{
sqlcmm.CommandText = "insert into register(users,sex,phone,pass,mail)values('"
+ this.txtuser.Text + "','" + this.txtsex.Text + "','"
+ this.txtnumber.Text + "','" + this.txtpass.Text + "','" + this.txtmail.Text + "')";
sqlcnn.Open();
sqlcmm.ExecuteNonQuery();
Response.Write("<script>alert('注册成功!')</script>");
}
}
}
else
{
Response.Write("<script>alert('您的口令卡密码不正确,请确认!')</script>");
}
}
}
}
- asp网站实现邮件的发送(注册为例)
- asp.net 实现邮箱验证(注册的时候发送邮件激活链接的那种)
- 教大家修改注册实现注册发送邮件的功能
- Node实现网站发送邮件的功能
- Domino为新注册的用户发送欢迎邮件
- asp.net实现一个用户进行注册的时候同时发送一个邮件到注册人的邮箱,通过发送的邮箱链接来激活该帐号
- asp.net实现一个用户进行注册的时候同时发送一个邮件到注册人的邮箱,通过发送的邮箱链接来激活该帐号
- asp Jmail发送邮件 注册提示
- ASP.NET实现邮件发送
- asp.net实现发送邮件
- ASP.NET ---- 实现邮件发送
- ASP实现在线发送邮件
- asp.net 实现发送邮件
- ASP.net实现邮件发送
- 使用qq邮箱SMTP服务器来为你的网站实现用户注册的邮件回复功能
- .NET实现注册发送邮件激活账户
- phpmailer实现发送注册验证邮件
- 网站通过gmail 实现邮件的发送功能
- 近来感悟
- 一个老程序员的生活总结
- ld.so.conf
- 施密特:Google六个月内推出高品质平板电脑
- 微软crypto API
- asp网站实现邮件的发送(注册为例)
- [shell] expect完整介绍
- GridView导出到excel
- GridView手动在后台增加-删除(1)
- Windows下截获程序的异常并进行处理
- C++ split字符串
- 嵌入式开发软件简介
- SharePoint2010项目中如何使用HttpModule
- define