电话
400 9058 355
要发送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./201702/yuanma/hovertreetop_jb51.rar
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
邮箱:8955556@qq.com
Q Q:8955556
这篇文章主要为大家详细介绍了Android自定义控件实现底部...
这篇文章主要介绍了Android中Toolbar随着Scro...
本文主要介绍了Java图表类库的相关知识。具有很好的参考价值...
本文主要介绍了GIt的基本操作。具有很好的参考价值,下面跟着...
共享内存是在两个正在运行的进程之间共享和传递数据的一种非常有...
这篇文章主要为大家详细介绍了Android自定义相机实现定时...
这篇文章主要介绍了CentOS6.5 上部署 MySQL5....
这篇文章主要介绍了Vue结合原生js实现自定义组件自动生成示...
最近在学习python网络编程这一块,在写简单的socket...
这篇文章主要介绍了微信小程序 数据交互与渲染实例详解的相关资...