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

Single Email Address Validation in C# and VB.NET

GemBox.Email contains a MailAddressValidator static class, which enables you to validate a single or a list of email addresses.

Email address validation has the following features:

  • Mail address format validation - The format of mail addresses passed as strings is checked first.
  • Domain name validation - Using the DNS protocol, the mail address validator will check if the domain exists and that it contains relevant mail records.
  • Mail server validation - The validator tests the connection to the mail server.
  • Mail address existence - The mail server reports if the specified mail address exists or not.

The following example shows how to validate a single mail address using the GemBox.Email library.

Screenshot
Single Address Validation Screenshot

See the full code below.

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

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

        // Incorrectly formatted mail address
        string address = " <invalid.address@gemboxsoftware.com";
        Console.Write("Validating address {0,-40} ... ", address);
        MailAddressValidationStatus result = MailAddressValidator.Validate(address);
        Console.WriteLine("[{0}]", result);

        // Non-existing mail address domain
        address = "invalid.domain@gemboxsoftware12345.com";
        Console.Write("Validating address {0,-40} ... ", address);
        result = MailAddressValidator.Validate(address);
        Console.WriteLine("[{0}]", result);

        // Non-existing mail address account
        address = "non.existing.address@gemboxsoftware.com";
        Console.Write("Validating address {0,-40} ... ", address);
        result = MailAddressValidator.Validate(address);
        Console.WriteLine("[{0}]", result);

        // Valid mail address
        address = "Info <info@gemboxsoftware.com>";
        Console.Write("Validating address {0,-40} ... ", address);
        result = MailAddressValidator.Validate(address);
        Console.WriteLine("[{0}]", result);
    }
}
Imports GemBox.Email

Module Samples

    Sub Main()

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

        ' Incorrectly formatted mail address
        Dim address As String = " <invalid.address@gemboxsoftware.com"
        Console.Write("Validating address {0,-40} ... ", address)
        Dim result As MailAddressValidationStatus = MailAddressValidator.Validate(address)
        Console.WriteLine("[{0}]", result)

        ' Non-existing mail address domain
        address = "invalid.domain@gemboxsoftware12345.com"
        Console.Write("Validating address {0,-40} ... ", address)
        result = MailAddressValidator.Validate(address)
        Console.WriteLine("[{0}]", result)

        ' Non-existing mail address account
        address = "non.existing.address@gemboxsoftware.com"
        Console.Write("Validating address {0,-40} ... ", address)
        result = MailAddressValidator.Validate(address)
        Console.WriteLine("[{0}]", result)

        ' Valid mail address
        address = "Info <info@gemboxsoftware.com>"
        Console.Write("Validating address {0,-40} ... ", address)
        result = MailAddressValidator.Validate(address)
        Console.WriteLine("[{0}]", result)

    End Sub

End Module

Check next sample.