Create Email in C# and VB.NET

GemBox.Email represents an email with a MailMessage object. This object provides properties for specifying or accessing the email's sender, recipient, subject, body and more. It's used for generating new or inspecting existing email messages.

The following example shows how to create a simple message, with subject and body, in a standard MIME format.

Screenshot of generated basic email
Creating an email in C# and VB.NET
using GemBox.Email;

class Program
{
    static void 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 = "Test email message with text body";
        message.BodyText = "This is a test message with text body.";

        message.Save("Create Message.%OutputFileType%");
    }
}
Imports GemBox.Email

Module Program

    Sub Main()

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

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

        ' Set subject And text body.
        message.Subject = "Test email message with text body"
        message.BodyText = "This is a test message with text body."

        message.Save("Create Message.%OutputFileType%")
    End Sub
End Module

With GemBox.Email, you can easily create more advanced mail messages as well; for instance, you can check out our:

  • Html With Attachment example, for creating emails with HTML content, CSS styling, embedded images and attachments.
  • Header example, for creating emails with built-in or custom mail message headers.
  • Calendar example, for creating emails with calendars.

Check next example or download examples from GitHub.