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

首頁 > 編程 > C# > 正文

通過C#實現發送自定義的html格式郵件

2020-01-24 00:47:29
字體:
來源:轉載
供稿:網友

要發送HTML格式郵件,需要設置MailMessage對象的IsBodyHtml屬性,設置為true。

類MailMessage在命名空間System.Net.Mail下。

using System.Net.Mail;

發送HTML格式的郵件在HoverTreeTop項目中已經實現,并發送成功。

需依賴于HoverTreeFrame項目的HoverTreeEmail類。

方法為:

復制代碼 代碼如下:

public static string HoverTreeSendEmail(string userName, string password, SmtpClient smtpClient, MailMessage mailMessage)

頁面截圖:

EmailSend.aspx頁面:

<h2>發送郵件</h2>  <br />收信人郵箱:<asp:TextBox runat="server" ID="textBox_mail" TextMode="Email" Columns="53" />  <br />標題:<asp:TextBox runat="server" ID="textBox_title" Columns="60" />  <br /><asp:CheckBox runat="server" ID="checkBox_isHtml" Text="是否HTML格式" />  <br />內容:  <br /><asp:TextBox runat="server" ID="textBox_content" TextMode="MultiLine" Rows="10" Columns="70" />  <br /> <asp:Button runat="server" ID="button_send" Text="發送郵件" OnClick="button_send_Click" />    <br />    <asp:Literal runat="server" ID="literal_tips" />

EmailSend.aspx.cs代碼:

using System;using System.Net.Mail;using HoverTree.HoverTreeFrame.HtNet;using HoverTreeTop.HtConfig.MyConfig;namespace HoverTreeTop.HoverTree.HoverTreePanel.HTPanel.HEmail{  public partial class EmailSend : System.Web.UI.Page  {    protected void Page_Load(object sender, EventArgs e)    {    }    protected void button_send_Click(object sender, EventArgs e)    {      //使用smtp來發送郵件      //literal_tips.Text = HoverTreeEmail.HoverTreeSendEmail("smtp.hovertree.com", "hello@.mail.hovertree.com", "hewenqi", "hello@mail.hovertree.com", "ht@mail.hovertree.com", "祝你生日快樂!", "生日快樂!天天開心! -- 何問起");      // literal_tips.Text = HoverTreeEmail.HoverTreeSendEmail(HtSmtpConfig.HtSmtpHost, HtSmtpConfig.HtSmtpUserName, HtSmtpConfig.HtSmtpPassword, HtSmtpConfig.HtSmtpFromEmail, textBox_mail.Text.Trim(), textBox_title.Text, textBox_content.Text);      SmtpClient h_smtpClient = new SmtpClient();      h_smtpClient.Host = HtSmtpConfig.HtSmtpHost;      MailMessage h_mailMessage = new MailMessage();      h_mailMessage.From = new MailAddress(HtSmtpConfig.HtSmtpFromEmail);      h_mailMessage.To.Add(textBox_mail.Text.Trim());      h_mailMessage.Subject = textBox_title.Text.Trim();      h_mailMessage.Body = textBox_content.Text;      h_mailMessage.IsBodyHtml = checkBox_isHtml.Checked;      literal_tips.Text = HoverTreeEmail.HoverTreeSendEmail(HtSmtpConfig.HtSmtpUserName, HtSmtpConfig.HtSmtpPassword, h_smtpClient, h_mailMessage);      if (literal_tips.Text == "")      {        literal_tips.Text = "發送成功!";        textBox_content.Text = "";        textBox_title.Text = "";        textBox_mail.Text = "";      }    }  }}

用于發送的示例內容:

<html><body>  <h2>C#發送html格式的郵件 </h2>  <div style="background-color:green;width:200px;height:100px;color:white">HoverTreeTop</div></body></html>

代碼下載:http://xiazai.VeVB.COm/201702/yuanma/hovertreetop_jb51.rar

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

上一篇:C#知識整理

下一篇:一個狀態機的實現

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 申扎县| 十堰市| 长丰县| 自贡市| 萝北县| 秦安县| 图木舒克市| 大理市| 应城市| 道真| 东阿县| 年辖:市辖区| 望谟县| 乌拉特前旗| 台湾省| 祥云县| 泉州市| 曲沃县| 云龙县| 南皮县| 无棣县| 景洪市| 海宁市| 红河县| 社会| 南溪县| 新野县| 玉林市| 肇东市| 博兴县| 桦甸市| 漳平市| 永吉县| 军事| 临洮县| 监利县| 桐柏县| 资中县| 泰来县| 门头沟区| 和硕县|