Code case for sending custom HTML-formatted messages using C #

Source: Internet
Author: User
Tags mailmessage smtpclient
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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.