1. 添加命名空间
using System.Net.Mail; using System.Net;
2. The HTML MarpUp
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> <asp:Label ID="Label1" runat="server" Text="From:"></asp:Label> </td> <td> <asp:TextBox ID="txtFrom" runat="server" Height="17px" Width="231px"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label3" runat="server" Text="To:"></asp:Label> </td> <td> <asp:TextBox ID="txtTo" runat="server" Height="19px" Width="226px"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label2" runat="server" Text="Subject:"></asp:Label> </td> <td> <asp:TextBox ID="txtSubject" runat="server" Height="19px" Width="240px"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label4" runat="server" Text="Body:"></asp:Label> </td> <td> <asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Height="102px" Width="234px"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label5" runat="server" Text="Accachment:"></asp:Label> </td> <td> <asp:FileUpload ID="FileUpload1" runat="server" /> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click" /> </td> </tr> </table> </div> </form> </body> </html>