This article mainly introduces the use of C # to send custom HTML-formatted messages, detailed introduction of the method of sending HTML-formatted messages, interested to understand.
To send an HTML-formatted message, set the Isbodyhtml property of the MailMessage object to True.
The class MailMessage under namespace System.Net.Mail.
Using System.Net.Mail;
Messages sent in HTML format have been implemented in the Hovertreetop project and sent successfully.
Depends 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 )
Page:
Emailsend.aspx page:
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, Eventar GS e) {//Use SMTP to send mail//literal_tips. Text = Hovertreeemail.hovertreesendemail ("smtp.hovertree.com", "hello@.mail.hovertree.com", "Hewenqi", "Hello@mail". Hovertree.com "," ht@mail.hovertree.com "," Wish you a happy birthday! " "Happy Birthday!" Happy every day! --"What to ask"); 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 = "Send successfully!" "; Textbox_content. Text = ""; Textbox_title. Text = ""; Textbox_mail. Text = ""; } } }}
Sample content for sending: