How to Send HTML-Formatted Email Using C#
- 
          
            Create Windows Form to Send HTML-Formatted Email Using C#
- 
          
            Write the Code to Send HTML-Formatted Email Using C#
 
This article will teach you how to send HTML-formatted emails using C# in ASP.Net.
Sending emails over SMTP may be tested with either your current Gmail account or a whole new account. The Gmail Mailer client can be used for communication.
Create Windows Form to Send HTML-Formatted Email Using C#
- 
Add a label and textbox forUser Name. This will be the sender’s username. 
- 
Add a label and textbox forPassword. It will be the sender account’s password. 
- 
Add a label and textbox forSendto. It will be the receiver’s mail address. 
- 
Add a label and textbox forSubjector title. 
- 
Lastly, create a button namedSend Mail. The complete form will look like this:  
Write the Code to Send HTML-Formatted Email Using C#
Below are the necessary steps to write the code to send HTML-formatted email using C#:
- 
To begin, import the following libraries:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Mail;
- 
CreateMailMessageobject andSmtpClientobject.MailMessage mail = new MailMessage(); SmtpClient smtp = new SmtpClient("smtp.gmail.com");
- 
Now, assign values of properties like sender, receiver, subject, body, etc.mail.To.Add(sendtotxt.Text); mail.Subject = subjecttxt.Text; var htmlbody = "Here your can write your html"; mail.Body = htmlbody; smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential(usertxt.Text, passtxt.Text);
- 
EnableSSL, and send the message.smtp.EnableSsl = true; smtp.Send(mail);
Complete Source Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Mail;
namespace EmailExample {
  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
    }
    private void sendbtn_Click(object sender, EventArgs e) {
      try {
        MailMessage mail = new MailMessage();
        SmtpClient smtp = new SmtpClient("smtp.gmail.com");
        mail.From = new MailAddress(usertxt.Text);
        mail.To.Add(sendtotxt.Text);
        mail.Subject = subjecttxt.Text;
        var htmlbody = "Here your can write your html";
        mail.Body = htmlbody;
        smtp.Port = 587;
        smtp.Credentials = new System.Net.NetworkCredential(usertxt.Text, passtxt.Text);
        smtp.EnableSsl = true;
        smtp.Send(mail);
        MessageBox.Show("Mail Sent!");
      } catch (Exception ex) {
        MessageBox.Show(ex.Message);
      }
    }
  }
}
Output:

I have been working as a Flutter app developer for a year now. Firebase and SQLite have been crucial in the development of my android apps. I have experience with C#, Windows Form Based C#, C, Java, PHP on WampServer, and HTML/CSS on MYSQL, and I have authored articles on their theory and issue solving. I'm a senior in an undergraduate program for a bachelor's degree in Information Technology.
LinkedIn