smtpemail.aspx.cs

来自「Microsoft?ASP.NET Programming with Micro」· CS 代码 · 共 96 行

CS
96
字号
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mail;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Chapter_08
{
	/// <summary>
	/// Summary description for SmtpEmail.
	/// </summary>
	public class SmtpEmail : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.TextBox TextBox3;
		protected System.Web.UI.WebControls.TextBox TextBox4;
		protected System.Web.UI.WebControls.TextBox TextBox5;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.Label Status;
		protected System.Web.UI.HtmlControls.HtmlTable MailTable;
		protected System.Web.UI.HtmlControls.HtmlInputButton Reset1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#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.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)
		{
			// Create MailMessage instance, set properties, and send
			MailMessage Mail = new MailMessage();

			Mail.To = TextBox1.Text;
			Mail.Cc = TextBox2.Text;
			Mail.Bcc = TextBox3.Text;
			Mail.Subject = TextBox4.Text;
			Mail.Body = TextBox5.Text;

			// Set the property below to a valid email address
			Mail.From = "feedback@aspnetsbs.com";
			SmtpMail.SmtpServer = "localhost";
			SmtpMail.Send(Mail);

			// Use the first label to display status
			Status.Text = "Mail Sent";

			// Hide the table
			MailTable.Visible = false;

			// Add a Hyperlink control to allow sending another email
			HyperLink Link = new HyperLink();
			Link.Text = "Click here to send another email.";
			Link.NavigateUrl = "SmtpEmail.aspx";

			// This line is only necessary if the page is in GridLayout mode
			Link.Attributes["Style"] = "LEFT: 8px; POSITION: absolute; TOP: 50px";
			Page.Controls.Add(Link);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?