private void Button1_Click(object sender, System.EventArgs e)
{
if(IsValid)
{
Label13.Text="Welcome "+ TextBox1.Text +" "+TextBox2.Text + ".You have successfully registered.";
HttpCookie mycookie=new HttpCookie("WebShoppe","You have visited the WebShoppe Site.");
mycookie.Expires=System.Convert.ToDateTime("12/12/2005");
Response.Cookies.Add(mycookie);
MailMessage msg = new MailMessage();
StringWriter strwriter =new StringWriter();
HtmlTextWriter htmltxtwriter =new HtmlTextWriter(strwriter);
htmltxtwriter.RenderBeginTag("html");
htmltxtwriter.RenderBeginTag("head");
htmltxtwriter.RenderBeginTag("title");
htmltxtwriter.Write("Thank You!");
htmltxtwriter.RenderEndTag();
htmltxtwriter.RenderEndTag();
htmltxtwriter.RenderBeginTag("body");
htmltxtwriter.WriteLine("Thank you for registering with WebShoppe Site!");
htmltxtwriter.RenderEndTag();
htmltxtwriter.RenderEndTag();
msg.From ="pangtianbing@126.com"; //要用在126smtp中注册过的邮箱,并和下面代码中的注册名及密码要相符
msg.To=TextBox12.Text;
msg.Bcc="tangjingtian123@hotmail.com";
msg.Subject="Thanks for registering";
msg.Body=strwriter.ToString();
msg.BodyFormat=MailFormat.Html;
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //确认需要认证
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "pangtianbing"); //设置在smtp中使用的用户名
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "**********"); //设置在smtp中使用的密码.
SmtpMail.SmtpServer="smtp.126.com";
SmtpMail.Send(msg);
}
}