学习中的问题

1winform

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;

namespace _130104
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string[] x = textBox1.Text.Split(',');
foreach (string u in x)
{
fasong(u);

}
MessageBox.Show("发送成功");


}

private void fasong(string u)
{

MailMessage msg = new MailMessage();//邮件本身

msg.Body = this.textBox3.Text;
msg.Subject = this.textBox2.Text;
// MailAddress madd = new MailAddress(textBox1.Text);
msg.From = new MailAddress("603301422@qq.com");
msg.To.Add("" + u + "");
//msg.Sender=new MailAddress("1478433927@qq.com")

SmtpClient client = new SmtpClient();//代理
client.Host = "smtp.qq.com";//发件方的服务器地址
client.Port = 25;//发件方端口,可以省略

NetworkCredential credetial = new NetworkCredential();//证书
credetial.UserName = "603301422";
credetial.Password = "xiaoweizhe2009";

client.Credentials = credetial;
client.Send(msg);//发送邮件

}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
MessageBox.Show("不同邮件由逗号隔开");
}
else {

}
}
}
}

2

注册页面

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.Net.Mail;
using System.Net;
using System.Text;

namespace _1314
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
string constr = ConfigurationManager.ConnectionStrings["aaa"].ConnectionString;
protected void Button2_Click(object sender, EventArgs e)
{
string u = TextBox1.Text;
string p = TextBox2.Text;
string em = TextBox3.Text;
string suiji=Guid.NewGuid().ToString().Substring(0,8);
int num = 0;

using (SqlConnection con = new SqlConnection(constr))
{
string sql = "insert into yonghu (username,pass,email,yanzheng,suiji) values(@username,@pass,@email,@yanzheng,@suiji)";

SqlParameter[] prm = new SqlParameter[]{
new SqlParameter("@username",u),
new SqlParameter("@pass",p),
new SqlParameter("@email",em),
new SqlParameter("@yanzheng",false),
new SqlParameter("@suiji",suiji)

};
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
cmd.Parameters.AddRange(prm);
num= cmd.ExecuteNonQuery();
}
}
if (num > 0)
{
int id= deid();
senmail(em, suiji,id);
Response.Redirect("WebForm2.aspx");
}
else {
Response.Write("注册失败");

}

}
public int deid() {
using (SqlConnection con = new SqlConnection(constr))
{
string sql = "select count(*) from yonghu";

string num = "";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
//cmd.Parameters.AddRange(prm);
num = cmd.ExecuteScalar().ToString();
return Convert.ToInt32(num);

}
}

}
public void senmail(string email, string suiji,int id)
{


MailMessage msg = new MailMessage();//邮件本身


msg.Subject ="请激活";
StringBuilder content = new StringBuilder();
content.Append("请单击一下连接激活");
content.Append("<a href='http://localhost:8899/WebForm3.aspx?suiji="+suiji+"&id="+id+"'>激活</a>");
msg.Body =content.ToString();
msg.IsBodyHtml = true;
// MailAddress madd = new MailAddress(textBox1.Text);
msg.From = new MailAddress("603301422@qq.com");
msg.To.Add(""+email+"");
//msg.Sender=new MailAddress("1478433927@qq.com")

SmtpClient client = new SmtpClient();//代理
client.Host = "smtp.qq.com";//发件方的服务器地址
client.Port = 25;//发件方端口,可以省略

NetworkCredential credetial = new NetworkCredential();//证书
credetial.UserName = "603301422";
credetial.Password = "xiaoweizhe2009";

client.Credentials = credetial;
client.Send(msg);//发送邮件


}
}
}

提示注册成功页面

<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="_1314.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
注册成功请到邮箱注册,
</div>
</form>
</body>
</html>

更改数据库网页

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace _1314
{
public partial class WebForm3 : System.Web.UI.Page
{
string constr = ConfigurationManager.ConnectionStrings["aaa"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
string x = Request["suiji"];
string id = Request["id"];
string num="";

using (SqlConnection con = new SqlConnection(constr))
{
string sql = "select suiji from yonghu where id="+id+" ";


using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
//cmd.Parameters.AddRange(prm);
num = cmd.ExecuteScalar().ToString();
if (num.ToString()==x)
{
xx(Convert.ToInt32(id));
}
}
}
}
public void xx(int id) {

using (SqlConnection con = new SqlConnection(constr))
{
string sql = "update yonghu set yanzheng=1 where id=" + id + " ";


using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
//cmd.Parameters.AddRange(prm);
cmd.ExecuteNonQuery();
Response.Write("验证成功");

}
}

}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值