日期:2014-03-29 浏览次数:21118 次
页代码如下
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
//下面两个是新引入的命名空间,1是邮件,2是IO
using System.Web.Mail;
using System.IO;
namespace mation
{
/**//// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox Textbox4;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.HtmlControls.HtmlTable Table1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
FileStream fs=new FileStream(Server.MapPath("db.xml"),FileMode.Open,FileAccess.Read);//创建文本流
StreamReader sr=new StreamReader(fs);//创建读取器
DataSet ds=new DataSet();//声明一个本地表
ds.ReadXml(sr);//将内容装载到本地表中
this.DropDownList1.DataSource=ds.Tables[0];//设置数据源
this.DropDownList1.DataTextField="bumen";//设置显示的文本字段
this.DropDownList1.DataValueField="addr";//对应的值
this.DropDownList1.DataBind();//绑定
}
//这里是窗体设计器生成的代码
private void Button1_Click(object sender, System.EventArgs e)
{
//创建音讯文本
string the="新的音讯<br>名字:"+TextBox1.Text.ToString()+"<br>邮件地址:"+TextBox2.Text.ToString()+"<br>意见是:"+TextBox3.Text.ToString();//结构邮件注释内容
// Response.Write(the);
MailMessage mm=new MailMessage();//实例化一个Email对象
mm.From=TextBox2.Text.ToString();//前往发信人的地址
mm.To=this.DropDownList1.SelectedItem.Value;//收信人的地址,也就是邮件的目标地址
mm.Subject=this.Textbox4.Text.ToString();//邮件标题
mm.Body=the;//邮件注释
&nbs