|
技术资料 > .Net专区 > Asp.Net开发 : 邮件发送测试--Codebehind |
邮件发送测试--Codebehind March 25,2004 |
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Blood.Com.ClassLib;
namespace Test
{
/// <summary>
/// 邮件发送例子
/// </summary>
public class SendMailSample : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.DropDownList ddlPriority;
protected System.Web.UI.WebControls.DropDownList ddlHtml;
protected System.Web.UI.WebControls.TextBox txtSmtpHost;
protected System.Web.UI.WebControls.TextBox txtPort;
protected System.Web.UI.WebControls.TextBox txtFrom;
protected System.Web.UI.WebControls.TextBox txtFromName;
protected System.Web.UI.WebControls.TextBox txtTo;
protected System.Web.UI.WebControls.TextBox txtToName;
protected System.Web.UI.WebControls.TextBox txtSubject;
protected System.Web.UI.WebControls.TextBox txtMessage;
protected System.Web.UI.WebControls.RegularExpressionValidator revPort;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvSmtpHost;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvPort;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvFrom;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvTo;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvSubject;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvMessage;
protected System.Web.UI.WebControls.Button btnSendMail;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.RegularExpressionValidator revFrom;
protected System.Web.UI.WebControls.RegularExpressionValidator revTo;
protected System.Web.UI.WebControls.Panel pelMessage;
private void Page_Load(object sender, System.EventArgs e)
{
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSendMail.Click += new System.EventHandler(this.btnSendMail_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSendMail_Click(object sender, System.EventArgs e)
{
if(IsPostBack)
{
SMTPMail clsMail = new SMTPMail();
string strSmtpHost = txtSmtpHost.Text;
int intPort = Int32.Parse(txtPort.Text);
string strFrom = txtFrom.Text;
string strFromName = txtFromName.Text;
string strTo = txtTo.Text;
string strToName = txtToName.Text;
SMTPMail.Prioritys Priority = SMTPMail.Prioritys.NORMAL;
bool bolHtml;
string strSubject = txtSubject.Text;
string strMessage = txtMessage.Text;
if(ddlPriority.SelectedItem.Text == "默认")
{
Priority = SMTPMail.Prioritys.NORMAL;
}
else if(ddlPriority.SelectedItem.Text == "高")
{
Priority = SMTPMail.Prioritys.HIGH;
}
else if(ddlPriority.SelectedItem.Text == "低")
{
Priority = SMTPMail.Prioritys.LOW;
}
if(ddlHtml.SelectedItem.Text == "是")
{
bolHtml = true;
}
else
{
bolHtml = false;
}
clsMail.SendMail(strSmtpHost,intPort,strFrom,strFromName,strTo,strToName,Priority,bolHtml,"",strSubject,strMessage);
if(clsMail.ErrorMessage !="")
{
pelMessage.Visible = true;
lblMessage.Text = clsMail.ErrorMessage;
lblMessage.ForeColor = System.Drawing.Color.Red;
}
else
{
pelMessage.Visible = true;
lblMessage.Text = "邮件发送成功";
lblMessage.ForeColor = System.Drawing.Color.Blue;
}
}
}
}
} |
|
Copyright © 2001-2008 Shenzhen Hiblue Software Team All rights reserved