namespace tMail
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
MailMessage _MailMessage=new MailMessage();
string UserName="drk928";
string PassWord="horse";
string EmailServer="smtp.163.com";
protected System.Web.UI.WebControls.Button Button1;
string EmailTo="drk928@21cn.com";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private bool sendvalid()
{
this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
if (this.UserName != null && this.PassWord != null)
{
this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = this.UserName;
this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = this.PassWord;
}
this._MailMessage.To =this.EmailTo;
SmtpMail.SmtpServer =this.EmailServer;
try
{
SmtpMail.Send(this._MailMessage);
}
catch(Exception ex)
{
//this.WriteLogTxt("ErrorMessage:"+ex.Message,false);
return false;
}
return true;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
bool pd=sendvalid();
Response.Write(pd);
}
}
}