欧美日韩一区二区三区四区不卡,日韩欧美视频一区二区三区四区,久久精品欧美一区二区三区不卡,国产精品久久久乱弄

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學無止境
關注開優網絡 關注前沿
.NET 三種取整方法 向上取整 向下取整 四舍五入
C# string字符串的截取、移除、替換、插入

ASP.NET發送Emai

發表日期:2018-07-24    文章編輯:    瀏覽次數:4667    標簽:ASP.NET應用

1、前端.aspx


01.<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
02. 
03.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04. 
06.<head runat="server">
07.    <title>發送Email示例</title>
08.</head>
09.<body>
10.    <form id="form1" runat="server">
11.    <h1>發送Email示例</h1>
12.    <p>發件郵箱:<asp:TextBox ID="txtFrom" runat="server" Width="407px" Text="niunan@niunan.net"></asp:TextBox>
13.    </p>
14.    <p>用戶名:<asp:TextBox ID="txtName" runat="server" Width="407px" Text="niunan@niunan.net"></asp:TextBox>
15.    </p>
16.    <p>密碼:<asp:TextBox ID="txtPWD" runat="server" Width="407px" Text="nn13607886582"></asp:TextBox>
17.    </p>
18.    <p>SMTP地址:<asp:TextBox ID="txtSMTP" runat="server" Width="407px" Text="smtp.qq.com"></asp:TextBox>
19.    </p>
20.    <p>收件郵箱:<asp:TextBox ID="txtTo" runat="server" Width="407px" Text="164423073@qq.com"></asp:TextBox>
21.    </p>
22.    <p>標題:<asp:TextBox ID="txtTitle" runat="server" Width="407px" Text="test title"></asp:TextBox>
23.    </p>
24.    <p>內容:</p>
25.    <p>
26.        <asp:TextBox ID="txtContent" Text="test content" TextMode="MultiLine" runat="server" Height="125px" Width="432px"></asp:TextBox>
27.    </p>
28.    <p>
29.        <asp:Button ID="btnSend" runat="server" Text="發送" onclick="btnSend_Click" />
30.&nbsp;&nbsp;&nbsp;&nbsp;
31.        <asp:Label ID="lblMes" ForeColor="Red" runat="server" Text=""></asp:Label>
32.    </p>
33.    </form>
34.</body>
35.</html>


2、后臺.cs


01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using System.Web.UI;
06.using System.Web.UI.WebControls;
07.using System.Net.Mail;
08.using System.Net;
09. 
10.public partial class _Default : System.Web.UI.Page
11.{
12.    protected void Page_Load(object sender, EventArgs e)
13.    {
14. 
15.    }
16. 
17.    /// <summary>
18.    /// 發送email,默認是25端口
19.    /// </summary>
20.    /// <param name="title">郵件標題</param>
21.    /// <param name="body">郵件內容</param>
22.    /// <param name="toAdress">收件人</param>
23.    /// <param name="fromAdress">發件人</param>
24.    /// <param name="userName">發件用戶名</param>
25.    /// <param name="userPwd">發件密碼</param>
26.    /// <param name="smtpHost">smtp地址</param>
27.    private string sendMail(string title, string body, string toAdress, string fromAdress,
28.                          string userName, string userPwd, string smtpHost)
29.    {
30.        try
31.        {
32.            MailAddress to = new MailAddress(toAdress);
33.            MailAddress from = new MailAddress(fromAdress);
34.            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
35.            message.IsBodyHtml = true; // 如果不加上這句那發送的郵件內容中有HTML會原樣輸出
36.            message.Subject = title; message.Body = body;
37.            SmtpClient smtp = new SmtpClient();
38.            smtp.UseDefaultCredentials = true;
39.            smtp.Port = 25;
40.            smtp.Credentials = new NetworkCredential(userName, userPwd);
41.            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
42.            smtp.Host = smtpHost;
43.            message.To.Add(toAdress);
44.            smtp.Send(message);
45.            return "郵件發送成功!";
46.        }
47.        catch (Exception ex)
48.        {
49.            return ex.Message;
50.        }
51.    }
52. 
53.    protected void btnSend_Click(object sender, EventArgs e)
54.    {
55.        string title = txtTitle.Text.Trim();
56.        string content = txtContent.Text.Trim();
57.        string to = txtTo.Text.Trim();
58.        string from = txtFrom.Text.Trim();
59.        string username = txtName.Text.Trim();
60.        string pwd = txtPWD.Text.Trim();
61.        string smtp = txtSMTP.Text.Trim();
62. 
63.        lblMes.Text = sendMail(title, content, to, from, username, pwd, smtp);
64.    }
65.}


主站蜘蛛池模板: 平塘县| 南郑县| 和田县| 无锡市| 富宁县| 富民县| 资源县| 宁远县| 霍林郭勒市| 兴安盟| 旬邑县| 德州市| 乡宁县| 渝北区| 托克托县| 同仁县| 孝义市| 高青县| 富源县| 托克逊县| 江阴市| 丹东市| 六安市| 德州市| 綦江县| 镇平县| 防城港市| 彭州市| 遂溪县| 淮滨县| 江西省| 漳州市| 宿松县| 凤山市| 永昌县| 连平县| 甘南县| 称多县| 泸溪县| 盐山县| 炉霍县|