GemBox.Email is a .NET component that enables you to read, write, receive, and send emails from your .NET applications using one simple API.

Email Message in HTML

The GemBox.Email component supports creating mail messages with multiple body formats. The following example shows how to use the GemBox.Email .NET component to create a mail message with a styled HTML body.

Screenshot
Html Message Screenshot

See the full code below, use Run Example to execute.

using GemBox.Email;
using GemBox.Email.Mime;
using System;
using System.Collections.Generic;
using GemBox.Email.Smtp;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create new message
        MailMessage message = new MailMessage(new MailAddress("sender@example.com", "Sender"),
                              new MailAddress("first.receiver@example.com", "First receiver"));

        // Set subject and text body
        message.Subject = "HTML email message sample";

        // Set HTML body ...
        message.BodyHtml = "<html>" +
                              "<body style=\"background-color: #eae7e3;\">" +
                                 "<div style=\"background-color: lightblue; " + 
                                             "width: 500px; " +
                                             "margin: auto; " +
                                             "padding: 10px; " +
                                             "text-align: center\">" +
                                    "<h1 style=\"color: red\">" +
                                       "GemBox.Email<br/>Html Message sample" +
                                    "</h1>" +
                                    "<p style=\"text-align: left\">" +
                                       "This sample demonstrates how to create " +
                                        "<code style=\"color: blue\">" + 
                                           "GemBox.Email.MailMessage" +
                                        "</code> " +
                                        "with styled <b>HTML</b> body. " +
                                    "</p>" +
                                 "</div>" +
                              "</body>" +
                           "</html>";

        // ... and also, set text body for clients who doesn't support mail messages with HTML body
        message.BodyText = "GemBox.Email Html Message sample\r\n" +
                           "This sample demonstrates how to create " +
                           "GemBox.Email.MailMessage with styled HTML body.";

        message.Save("Html Message.eml");
    }
}
Imports GemBox.Email
Imports GemBox.Email.Mime
Imports GemBox.Email.Smtp

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        ' Create new message
        MailMessage message = new MailMessage(new MailAddress("sender@example.com", "Sender"),
                              new MailAddress("first.receiver@example.com", "First receiver"))

        ' Set subject And text body
        message.Subject = "HTML email message sample"

        ' Set HTML body ...
        message.BodyHtml = "<html>" &
                              "<body style=""background-color: #eae7e3"">" &
                                 "<div style=""background-color:lightblue; " &
                                             "width: 500px; " &
                                             "margin: auto; " &
                                             "padding: 10px; " &
                                             "text-align: center"">" &
                                    "<h1 style=""color:red"">" &
                                       "GemBox.Email<br/>Html Message sample" &
                                     "</h1>" &
                                     "<p style=""text-align:left"">" &
                                        "This sample demonstrates how to create " &
                                        "<code style=""color:blue"">" &
                                           "GemBox.Email.MailMessage" &
                                        "</code>" &
                                        "with styled <b>HTML</b> body." &
                                     "</p>" &
                                  "</div>" &
                               "</body>" &
                           "</html>"

        ' ... and also, set text body for clients who doesn't support mail messages with HTML body
        message.BodyText = "GemBox.Email Html Message sample" & vbCrLf &
                           "This sample demonstrates how To create " &
                           "GemBox.Email.MailMessage With styled HTML body."

        message.Save("Html Message.eml")

    End Sub

End Module

Check next sample.