Front Code:
<%@ Page language="C #"autoeventwireup="true"codefile="Default1.aspx.cs"inherits="DEFAULT1"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"><meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/> <title></title>"Form1"runat="Server"> <div>Please enter your e-mail address:<asp:textbox id="TextBox1"runat="Server"></asp:textbox><br/> <asp:button id="Button1"runat="Server"text="Send Verification Code"/><br/><br/>Please enter the verification code:<asp:textbox id="TextBox2"runat="Server"></asp:textbox><br/> <asp:button id="Button2"runat="Server"text="Validation"/> <asp:label id="Label1"runat="Server"text="Label"></asp:Label> </div> </form></body>Background code:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Net;usingSystem.Net.Mail; Public Partial classdefault1:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {Button1.Click+=button1_click; Button2.click+=button2_click; } voidButton2_Click (Objectsender, EventArgs e) { if(TextBox2.Text.Trim () = = session["YZM"]. ToString ()) {Label1.Text="OK"; } Else{Label1.Text="Error"; } } voidButton1_Click (Objectsender, EventArgs e) { //To create an SMTP call service classSmtpClient SMTP =NewSmtpClient ("smtp.sina.cn"); //Create sender ObjectMailAddress AAA =NewMailAddress ("[email protected]"); //Create a Recipient objectMailAddress to =Newmailaddress (TextBox1.Text); //Create a Mail objectMailMessage mail =NewMailMessage (aaa,to); //Populate message TopicsMail. subject="Verification code message from the registration of the sailing technology user"; //Populate message ContentMail. body="Your verification code is [1234], please fill in 20 minutes, this message is System mail, do not reply! "; session["YZM"] ="1234"; //Register a certificate, verify the sender's mailbox and passwordNetworkCredential net =NewNetworkCredential ("[email protected]","hq1234561"); //to associate a certificate to a server object waiting for validationSmtp. Credentials =net; //calling the Send methodSMTP. Send (mail); }}C # Send mail