通過(guò)C#實(shí)現(xiàn)發(fā)送自定義的html格式郵件
要發(fā)送HTML格式郵件,需要設(shè)置MailMessage對(duì)象的IsBodyHtml屬性,設(shè)置為true。
類MailMessage在命名空間System.Net.Mail下。
using System.Net.Mail;
發(fā)送HTML格式的郵件在HoverTreeTop項(xiàng)目中已經(jīng)實(shí)現(xiàn),并發(fā)送成功。
需依賴于HoverTreeFrame項(xiàng)目的HoverTreeEmail類。
方法為:
public static string HoverTreeSendEmail(string userName, string password, SmtpClient smtpClient, MailMessage mailMessage)
頁(yè)面截圖:
EmailSend.aspx頁(yè)面:
<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來(lái)發(fā)送郵件 //literal_tips.Text = HoverTreeEmail.HoverTreeSendEmail("smtp.hovertree.com", "hello@.mail.hovertree.com", "hewenqi", "hello@mail.hovertree.com", "ht@mail.hovertree.com", "祝你生日快樂(lè)!", "生日快樂(lè)!天天開(kāi)心! -- 何問(wèn)起"); // 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>
代碼下載:http://xiazai.jb51.net/201702/yuanma/hovertreetop_jb51.rar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- c# 兩種發(fā)送郵件的方法
- c# 實(shí)現(xiàn)發(fā)送郵件到指定郵箱
- c# 實(shí)現(xiàn)發(fā)送郵件的功能
- C# 服務(wù)器發(fā)送郵件失敗實(shí)例分析
- C#實(shí)現(xiàn)QQ郵箱發(fā)送郵件
- C#實(shí)現(xiàn)發(fā)送郵件的方法
- C# SendMail發(fā)送郵件功能實(shí)現(xiàn)
- C#實(shí)現(xiàn)的自定義郵件發(fā)送類完整實(shí)例(支持多人多附件)
- C#編程實(shí)現(xiàn)發(fā)送郵件的方法(可添加附件)
- C#實(shí)現(xiàn)發(fā)送郵件的三種方法
- c#利用system.net發(fā)送html格式郵件
- c#實(shí)現(xiàn)服務(wù)器性能監(jiān)控并發(fā)送郵件保存日志
- c#調(diào)用qq郵箱smtp發(fā)送郵件修改版代碼分享
- C#調(diào)用QQ_Mail發(fā)送郵件實(shí)例代碼兩例
相關(guān)文章
Unity中使用反射機(jī)制調(diào)用函數(shù)
這篇文章主要為大家詳細(xì)介紹了Unity中使用反射機(jī)制調(diào)用函數(shù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03c#利用Excel直接讀取數(shù)據(jù)到DataGridView
這個(gè)例子的功能是c#讀取excel文件,大家可以參考使用2013-11-11c#編寫(xiě)的高并發(fā)數(shù)據(jù)庫(kù)控制訪問(wèn)代碼
往往大數(shù)據(jù)量,高并發(fā)時(shí), 瓶頸都在數(shù)據(jù)庫(kù)上, 好多人都說(shuō)用數(shù)據(jù)庫(kù)的復(fù)制,發(fā)布, 讀寫(xiě)分離等技術(shù), 但主從數(shù)據(jù)庫(kù)之間同步時(shí)間有延遲.2015-03-03C#/VB.NET 自定義PPT動(dòng)畫(huà)路徑的步驟
這篇文章主要介紹了C#/VB.NET 自定義PPT動(dòng)畫(huà)路徑的步驟,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-05-05