Code example for sending custom html format emails using C#

黄舟
Release: 2017-03-23 11:52:08
Original
2413 people have browsed it

This article mainly introduces how to send customized html format emails throughC#, and introduces in detail the method of sending HTML format emails. Those who are interested can learn more.

To send HTML format emails, you need to set the IsBodyHtml property of the MailMessage object to true.

The class MailMessage is under the namespace System.Net.Mail.

using System.Net.Mail;
Copy after login

Sending emails in HTML format has been implemented in the HoverTreeTop project and was sent successfully.

Needs to depend on the HoverTreeEmail class of the HoverTreeFrame project.

The method is:

The code is as follows:

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

Page screenshot:

##EmailSend .aspx page:

发送邮件


收信人邮箱:
标题:

内容:


Copy after login

EmailSend.aspx.cs code:

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 = ""; } } } }
Copy after login

Sample content for sending:

  

C#发送html格式的邮件

HoverTreeTop

Copy after login

The above is the detailed content of Code example for sending custom html format emails using C#. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!