<%@ Page Language="VB" debug=true ClientTarget="downlevel" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.web" %>

<script language="VB" runat="server">
	Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
		Dim myMessage As New MailMessage
		Dim myMail    As New SmtpMail
		Dim strEmail  As String

		If Page.IsValid() Then
			strEmail = txtEmail.Text
			myMessage.From = txtEmail1.text
			myMessage.To = txtEmail.text
			myMessage.Subject = txtsub.text
			myMessage.Body = txtmessage.text
			myMessage.BodyFormat = MailFormat.Html
			myMessage.Priority = MailPriority.High				
			myMail.Send(myMessage)
'隐藏邮件发送的页面
			frmEmail.Visible = False
			lblUserMessage.Text = "您的信件已经成功的发送到了 " & strEmail & "."
		End If
	End Sub
</script>

<html>
<head>
<title>第四十例 使用ASP.NET发送Email</title>
</head>
<body>
		 <h3><font face="Verdana"> 第四十例 使用ASP.NET发送Email </font></h3><br> 
<asp:Label id="lblUserMessage" text="" runat="server" />
<form method="post" id="frmEmail" runat="server">
	<b>收 件 人地址:</b>
	<asp:TextBox id="txtEmail" size="30" runat="server" />
	<asp:RequiredFieldValidator runat="server"
		id="validEmailRequired" ControlToValidate="txtEmail"
		errormessage="必须输入收件人的Email."
		display="Dynamic" />
	<asp:RegularExpressionValidator runat="server"
		id="validEmailRegExp" ControlToValidate="txtEmail"
		ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
		errormessage="收件人Email地址无效."
		Display="Dynamic" />
	<BR>
	<b> 您 的 姓 名   :</b>
      <asp:textbox id="txtName" size="30" runat="server" />
      <br>
	<b> 主        题    :</b>
      <asp:textbox id="txtsub" size="30" runat="server" />
      <br>

      <b>您的Email地址:</b>
      <asp:textbox id="txtEmail1" size="30" runat="server" />
	<asp:RequiredFieldValidator runat="server"
		id="validEmailRequired1" ControlToValidate="txtEmail1"
		errormessage="必须输入发件人的Email."
		display="Dynamic" />
	<asp:RegularExpressionValidator runat="server"
		id="validEmailRegExp1" ControlToValidate="txtEmail1"
		ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
		errormessage="发件人Email地址无效."
		Display="Dynamic" />
     	<br>
      <b>邮件正文:</b><br>
      <asp:textbox id="txtMessage" TextMode="MultiLine"
                      Columns="40" Rows="10" runat="server" />
	<asp:RequiredFieldValidator runat="server"
		id="validEmailRequired2" ControlToValidate="txtmessage"
		errormessage="邮件的内容不能够为空."
		display="Dynamic" />
      <p>
	<asp:Button id="btnSendMail" text="立刻发送!" OnClick="btnSendMail_OnClick" runat="server" />
</form>

</body>
</html>
