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 Address Collection Validation in C# and VB.NET

Apart from validating a single mail address, the GemBox.Email component provides methods for validating a collection of mail addresses, using a MailAddressValidator static class. Address validation methods, that accept a collection parameter, are more efficient than validating an address collection in a loop. This is mainly because they group addresses with the same domain and validate them in one pass, which speeds up the process and lowers the resource usage and the possibility of IP blacklisting. The method returns a read-only collection of MailAddressValidationStatus values representing the results of the validation, in the same order as the provided collection of the addresses.

The following example shows how to verify a collection of mail addresses.

Screenshot
Address Collection 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");

        // Create a list of mail addresses
        List<MailAddress> addresses = new List<MailAddress>();

        addresses.Add(new MailAddress("invalid.domain@gemboxsoftware12345.com"));
        addresses.Add(new MailAddress("non.existing.address@gemboxsoftware.com"));
        addresses.Add(new MailAddress("non.existing.domain@gemboxsoftware12345.com"));
        addresses.Add(new MailAddress("info@gemboxsoftware.com"));

        Console.WriteLine("Validating addresses ... ");
        Console.WriteLine();

        // Validate address list and display results
        IList<MailAddressValidationStatus> results = MailAddressValidator.Validate(addresses);

        Console.WriteLine("|                   MAIL ADDRESS                     |            RESULT            |");
        Console.WriteLine("|----------------------------------------------------|------------------------------|");

        for (int i = 0; i < results.Count; i++)
            Console.WriteLine("| {0,-50} | {1,18} |", addresses[i], results[i]);

        Console.WriteLine("|----------------------------------------------------|------------------------------|");
    }
}
Imports GemBox.Email

Module Samples

    Sub Main()

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

        'Create a list of mail addresses
        Dim addresses As New List(Of MailAddress)

        addresses.Add(New MailAddress("invalid.domain@gemboxsoftware12345.com"))
        addresses.Add(New MailAddress("non.existing.address@gemboxsoftware.com"))
        addresses.Add(New MailAddress("non.existing.domain@gemboxsoftware12345.com"))
        addresses.Add(New MailAddress("info@gemboxsoftware.com"))

        Console.WriteLine("Validating addresses ... ")
        Console.WriteLine()

        ' Validate address list and display results
        Dim results As IList(Of MailAddressValidationStatus) = MailAddressValidator.Validate(addresses)

        Console.WriteLine("|                   MAIL ADDRESS                     |            RESULT            |")
        Console.WriteLine("|----------------------------------------------------|------------------------------|")

        For i As Integer = 0 To results.Count - 1
            Console.WriteLine("| {0,-50} | {1,18} |", addresses(i), results(i))
        Next

        Console.WriteLine("|----------------------------------------------------|------------------------------|")

    End Sub

End Module

Check next sample.