Use C # To send custom html emails,

Source: Internet
Author: User
Tags mailmessage smtpclient

Use C # To send custom html emails,

To send an HTML-formatted email, set the IsBodyHtml attribute of the MailMessage object to true.

The MailMessage class is in the namespace System. Net. Mail.
Using System. Net. Mail;

Emails in HTML format have been implemented in the HoverTreeTop project and sent successfully.
It depends on the HoverTreeFrame project's HoverTreeEmail class.
Method:
Public static string HoverTreeSendEmail (string userName, string password, SmtpClient smtpClient, MailMessage mailMessage)
Page:


EmailSend. aspx page:

<H2> send email 

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) {// use smtp to send emails // literal_tips.Text = HoverTreeEmail. hov ErTreeSendEmail ("smtp.hovertree.com", "hello @ .mail.hovertree.com", "hewenqi", "hello@mail.hovertree.com", "ht@mail.hovertree.com", "Happy birthday to you! "," Happy Birthday! Happy every day! -- He asked "); // literal_tips.Text = HoverTreeEmail. hoverTreeSendEmail (HtSmtpConfig. htSmtpHost, HtSmtpConfig. htSmtpUserName, HtSmtpConfig. htSmtpPassword, HtSmtpConfig. htSmtpFromEmail, delimiter (), textBox_title.Text, textBox_content.Text); SmtpClient h_smtpClient = new SmtpClient (); h_smtpClient.Host = HtSmtpConfig. htSmtpHost; MailMessage h_mailMessage = new MailMessage (); h_mailMessage.F Rom = new MailAddress (HtSmtpConfig. htSmtpFromEmail); h_mailMessage.To.Add (Response (); h_mailMessage.Subject = Response (); h_mailMessage.Body = textBox_content.Text; response = checkBox_isHtml.Checked; response = HoverTreeEmail. hoverTreeSendEmail (HtSmtpConfig. htSmtpUserName, HtSmtpConfig. htSmtpPassword, h_smtpClient, h_mailMessage); if (literal _ Tips. Text = "") {literal_tips.Text = "sent successfully! "; TextBox_content.Text =" "; textBox_title.Text =" "; textBox_mail.Text = "";}}}}

Sample content for sending:

<Html> <body> 

Reference: http://hovertree.com/h/bjag/swth6nfh.htm

Code download: http://hovertree.com/h/bjaf/hv6cqe5n.htm

More recommendations: http://www.cnblogs.com/sosoft/p/kaifajishu.html

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.