Load Email in C# and VB.NET

The following example shows how to load an email message from a file and display general message properties on console window.

Load Screenshot

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

Upload your file(Drag files here)

Download an input file

using GemBox.Email;
using GemBox.Email.Imap;
using GemBox.Email.Mime;
using GemBox.Email.Pop;
using GemBox.Email.Smtp;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

class Sample
    static void Main(string[] args)
        // If using Professional version, put your serial key below.

        // Load message
        MailMessage message = MailMessage.Load("Html.eml");
        StringBuilder sb = new StringBuilder();

        // Add date
        sb.AppendLine(string.Format("Date: {0}", message.Date));

        // Add addresses
        sb.AppendLine(string.Format("From: {0}", message.From.ToString()));
        sb.AppendLine(string.Format("To: {0}", message.To.ToString()));

        if (message.Cc.Count > 0)
            sb.AppendLine(string.Format("Cc: {0}", message.Cc.ToString()));

        if (message.Bcc.Count > 0)
            sb.AppendLine(string.Format("Bcc: {0}", message.Bcc.ToString()));

        if (message.Attachments.Count > 0)
            sb.AppendLine(string.Format("Attachments: {0}", message.Attachments.Count.ToString()));

        // Add subject
        sb.AppendLine(string.Format("Subject: {0}", message.Subject));

        // Add message body
        sb.AppendLine("------------------------------ BODY ------------------------------");
        if (string.IsNullOrEmpty(message.BodyHtml))

Imports System.Globalization
Imports System.Text
Imports GemBox.Email
Imports GemBox.Email.Imap
Imports GemBox.Email.Mime
Imports GemBox.Email.Pop
Imports GemBox.Email.Smtp

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.

        ' Load message
        Dim message as MailMessage = MailMessage.Load("Html.eml")
        Dim sb As New StringBuilder()

        ' Add date
        sb.AppendLine(String.Format("Date: {0}", message.Date))

        ' Add addresses
        sb.AppendLine(String.Format("From: {0}", message.From.ToString()))
        sb.AppendLine(String.Format("To: {0}", message.To.ToString()))

        If message.Cc.Count > 0 Then
            sb.AppendLine(String.Format("From: {0}", message.Cc.ToString()))
        End If

        If message.Bcc.Count > 0 Then
            sb.AppendLine(String.Format("From: {0}", message.Bcc.ToString()))
        End If

        If message.Attachments.Count > 0 Then
            sb.AppendLine(String.Format("Attachments: {0}", message.Attachments.Count.ToString()))
        End If

        ' Add subject
        sb.AppendLine(String.Format("Subject: {0}", message.Subject))

        ' Add message body
        sb.AppendLine("------------------------------ BODY ------------------------------")
        If String.IsNullOrEmpty(message.BodyHtml) Then
        End If


    End Sub

End Module