1、在web.config中的<configuration>内加入如下配置信息(host—smtp服务地址;port—端口号;userName—用户名;password—密码。请自行修改)。 <system.net>
<mailSettings> <smtp> <network host="smtpserver" port="25" userName="uid" password="pwd" /> </smtp> </mailSettings> </system.net> 2、aspx页面HTML代码 ![]() ![]() <table border="0"> <tr> <td> 发件人 </td> <td> <asp:TextBox runat="server" ID="emailfrom"></asp:TextBox> </td> </tr> <tr> <td> 收件人 </td> <td> <asp:TextBox runat="server" ID="emailto"></asp:TextBox> </td> </tr> <tr> <td> 主题 </td> <td> <asp:TextBox runat="server" ID="subject"></asp:TextBox> </td> </tr> <tr> <td> 附件 </td> <td> <asp:FileUpload ID="attachment" runat="server" /> </td> </tr> <tr> <td> 内容 </td> <td> <asp:TextBox runat="server" ID="body" TextMode="MultiLine" Columns="50" Rows="10"></asp:TextBox> </td> </tr> <tr> <td colspan="2" align="center"> <asp:Button runat="server" ID="btnSend" Text="发送" OnClick="btnSend_Click" /> </td> </tr> </table> 3、实例化一个MailMessage并设置其属性 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 4、实例化一个SmtpClient,调用其Send方法,参数为MailMessage对象 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|
来自: 悟静 > 《.net和asp.net》