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;
using System.Web.Mail;
namespace baoge
{
	/// <summary>
	/// sentMail 的摘要说明。
	/// </summary>
	public class sentMail : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblMsg;
		protected System.Web.UI.WebControls.TextBox txtTo;
		protected System.Web.UI.WebControls.TextBox txtFrom;
		protected System.Web.UI.WebControls.TextBox txtSubject;
		protected CuteEditor.Editor Editor1;
		protected System.Web.UI.WebControls.Button btnSend;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("admin/Admin_Login.aspx");
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSend_Click(object sender, System.EventArgs e)
		{
			//创建MailMessage对象
			MailMessage mailMsg = new MailMessage();
			//设置收件人的邮件地址
			mailMsg.To = txtTo.Text;
			//设置发送者的邮件地址
			mailMsg.From = txtFrom.Text;
			//设置邮件主题
			mailMsg.Subject = txtSubject.Text;
			//设置邮件内容
			mailMsg.Body = this.Editor1.Text;
			//设置支持服务器验证
			mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
			//设置用户名
			mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","baogecms@163.com");
			//设置用户密码
			mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","000000");
			//			try
			//			{
			//设置发送邮件服务器
			SmtpMail.SmtpServer = "smtp.163.com";
			//发送邮件
			SmtpMail.Send(mailMsg);
			lblMsg.Text = "发送成功";
			//			}
			//			catch
			//			{
			//				lblMsg.Text = "发送失败";
			//			}
		}
	}
}
