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

首頁 > 編程 > C# > 正文

通過C#實現(xiàn)發(fā)送自定義的html格式郵件

2019-10-29 21:14:42
字體:
供稿:網(wǎng)友

要發(fā)送HTML格式郵件,需要設(shè)置MailMessage對象的IsBodyHtml屬性,設(shè)置為true。

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

using System.Net.Mail;

發(fā)送HTML格式的郵件在HoverTreeTop項目中已經(jīng)實現(xiàn),并發(fā)送成功。

需依賴于HoverTreeFrame項目的HoverTreeEmail類。

方法為:

 

復(fù)制代碼 代碼如下:

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

 

頁面截圖:

c#發(fā)送html格式的郵件,.net,發(fā)送html郵件

EmailSend.aspx頁面:

<h2>發(fā)送郵件</h2>  <br />收信人郵箱:<asp:TextBox runat="server" ID="textBox_mail" TextMode="Email" Columns="53" />  <br />標(biāo)題:<asp:TextBox runat="server" ID="textBox_title" Columns="60" />  <br /><asp:CheckBox runat="server" ID="checkBox_isHtml" Text="是否HTML格式" />  <br />內(nèi)容:  <br /><asp:TextBox runat="server" ID="textBox_content" TextMode="MultiLine" Rows="10" Columns="70" />  <br /> <asp:Button runat="server" ID="button_send" Text="發(fā)送郵件" 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來發(fā)送郵件      //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 = "發(fā)送成功!";        textBox_content.Text = "";        textBox_title.Text = "";        textBox_mail.Text = "";      }    }  }}

用于發(fā)送的示例內(nèi)容:

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到c#教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 潮州市| 金湖县| 武安市| 金华市| 治多县| 睢宁县| 灵山县| 绥滨县| 绵阳市| 玛曲县| 林口县| 阿拉善右旗| 武强县| 阳泉市| 溧水县| 盘锦市| 乃东县| 清丰县| 拜泉县| 合水县| 定安县| 富锦市| 宾阳县| 类乌齐县| 荆州市| 达州市| 运城市| 平阴县| 永顺县| 靖安县| 溧阳市| 襄垣县| 清水县| 沾益县| 昌宁县| 青浦区| 遂昌县| 昭通市| 海原县| 常州市| 绥化市|