c#修改html文件内容,通过C#实现发送自定义的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)

页面截图:

fa86e713e3ad1e0220ea83cb9442d47e.png

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值