国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net2.0實現郵件發送(測試成功)

2024-07-10 13:22:03
字體:
來源:轉載
供稿:網友
1、Default.aspx代碼如下:

復制代碼 代碼如下:


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>無標題頁</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
        <table id="TABLE1" runat="server" border="0" cellpadding="0" cellspacing="0"> 
            <tr> 
                <td style="width: 393px"> 
                    收信:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> 
                    主題:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> 
                    內容:<asp:TextBox ID="TextBox3" runat="server" Height="154px" TextMode="MultiLine" 
                        Width="336px"></asp:TextBox><br /> 
                    <asp:Button ID="Button1" runat="server" Text="發送" OnClick="Button1_Click" /></td> 
            </tr> 
        </table> 

    </div> 
        <table id="Table2" runat="server" border="0" cellpadding="0" cellspacing="0" visible="false"> 
            <tr> 
                <td align="center" style="width: 400px"> 
                    <asp:Label ID="Label1" runat="server" ForeColor="Red" Text="恭喜您,發表成功!"></asp:Label><br /> 
                    <asp:Button ID="Button2" runat="server" Text="返回" OnClick="Button2_Click" /></td> 
            </tr> 
        </table> 
    </form> 
</body> 
</html> 




2、Default.aspx.cs代碼如下:

復制代碼 代碼如下:


using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
//倒入命名空間 
using System.Net; 
using System.Net.Mail; 

public partial class _Default : System.Web.UI.Page  

    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        ////設置發件人信箱,及顯示名字 
        MailAddress from = new MailAddress("zgdx0503@cpp114.com", "延邊職大信息中心"); 
        //設置收件人信箱,及顯示名字  
        MailAddress to = new MailAddress(TextBox1.Text, "0503班"); 
        //創建一個MailMessage對象 
        MailMessage oMail = new MailMessage(from, to);  

        oMail.Subject = TextBox2.Text;      //郵件標題        
        oMail.Body = TextBox3.Text;         //郵件內容 

        oMail.IsBodyHtml = true;            //指定郵件格式,支持HTML格式         
        oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");//郵件采用的編碼         
        oMail.Priority = MailPriority.High;//設置郵件的優先級為高 

        //發送郵件服務器 
        SmtpClient client = new SmtpClient(); 
        client.Host = "mail.cpp114.com";    //指定郵件服務器 
        client.Credentials = new NetworkCredential("zgdx0503@cpp114.com", "123456");//指定服務器郵件,及密碼 

        //發送 
        try 
        { 
            client.Send(oMail);  //發送郵件 
            Label1.Text = "恭喜你!郵件發送成功。"; 
        } 
        catch 
        { 
            Label1.Text = "郵件發送失敗,檢查網絡及信箱是否可用。"; 
        } 

        oMail.Dispose();        //釋放資源 

        TABLE1.Visible = false; 
        Table2.Visible = true; 
    } 
    protected void Button2_Click(object sender, EventArgs e) 
    { 
        //返回,繼續發送 
        Response.Redirect(Request.Url.ToString()); 
        TABLE1.Visible = true; 
        Table2.Visible = false; 
    } 



3、運行并輸入測試信箱zgdx0503@tom.com,(密碼:123456)。如下所示:

asp.net2.0實現郵件發送(測試成功)


4、打開信箱查看

asp.net2.0實現郵件發送(測試成功)

 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新民市| 广丰县| 眉山市| 黄浦区| 兴宁市| 巴马| 察隅县| 山阴县| 安福县| 博客| 泰和县| 尤溪县| 岳阳县| 茂名市| 淅川县| 石台县| 宿州市| 永德县| 成都市| 永州市| 肥东县| 天祝| 莒南县| 景泰县| 墨玉县| 高邮市| 潜江市| 连南| 沛县| 鹤峰县| 常山县| 咸丰县| 常熟市| 留坝县| 嘉禾县| 平谷区| 武穴市| 会东县| 塔河县| 海阳市| 蒙阴县|