本篇文章主要介绍了通过c#实现发送自定义的html格式邮件,详细的介绍了发送html格式邮件的方法,有兴趣的可以了解一下。
要发送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页面:
发送邮件
收信人邮箱:
标题:
内容:
登录后复制
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 = ""; } } }}
登录后复制
用于发送的示例内容:
C#发送html格式的邮件
HoverTreeTop
登录后复制
以上就是使用C#实现发送自定义的html格式邮件的代码案例的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2444747.html