EmailAddressValidatorVerify Method (DataTable, String)
Validates e-mail addresses in the data table given.

Namespace: MailBee.AddressCheck
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
public void Verify(
	DataTable emails,
	string columnName


Type: System.DataDataTable
The data table, in columnName column containing the e-mail addresses to check for syntax and, optionally, for existence.
Type: SystemString
The name of column in the given data table, containing the e-mail addresses.
MailBeeInvalidArgumentExceptionemails or columnName is a null reference (Nothing in Visual Basic), columnName is an empty string, or DnsServers collection is empty.
MailBeeUserAbortExceptionThe user code has aborted the component with Abort method.

To analyze the results, subscribe to Verified event. To implement blacklist or whitelist, subscribe to Verifying event.

For more info and tutorials, refer to Getting started with Address Validator guide.

This sample builds a data table with some e-mail addresses, and verifies them (in real apps, you'll usually get data from database). For performance sake, multi-threading is in use.
Note Note
Unlike similar sample in Getting started with Address Validator guide, the sample below also shows how to deal with race conditions. The sample below uses StreamWriter class to save results in a file. However, this class is not thread-safe. In multi-threaded scenario, you can get situation when multiple threads will try to write into the same file. This is not a problem when MailBee writes from many threads into a single log file (Log property) because it's controlled by MailBee. But StreamWriter instance was created by our own application and needs its own thread synchronizing.
using System;
using System.IO;
using System.Data;
using MailBee;
using MailBee.AddressCheck;

class Program
    private static object syncObject = new object();
    private static StreamWriter sw;

    // This method will be executed for each e-mail address in the bulk,
    // whenever it gets verified, with either positive or negative result.
    private static void valid_Verified(object sender, VerifiedEventArgs e)
        Console.WriteLine("*** Verified ***");
        Console.WriteLine("Email: " + e.Email);
        Console.WriteLine("Result: " + e.Result.ToString());
        if (e.Reason != null)
            Console.WriteLine("Reason: " + e.Reason.Message);

            // This lock guarantees only one thread at a time will execute the guarded section.
            lock (syncObject)
                sw.WriteLine(string.Format("{0}={1}", e.Email, e.Result.ToString()));
        catch (Exception ex)
            // This is also important. In multi-threaded mode, crashing due to an exception simply
            // closes the worker thread and you may never know what really happened. Thus, it's recommended
            // (at least in debug) to catch all exceptions there and print them out (such as to Console).

    static void Main(string[] args)
        EmailAddressValidator valid = new EmailAddressValidator("MN110-0123456789ABCDEF-0123");

        // To perform DNS MX lookup queries, we need some DNS servers for that.

        // Logging into a file is not required for the component to work
        // but helpful for debugging and understanding things under the hood.
        // Since this sample is multi-threaded, we also set AddContextInfo option
        // to make it easier analyze the log (each record will be tagged with a thread ID).
        valid.Log.Enabled = true;
        valid.Log.Format = LogFormatOptions.AddContextInfo;
        valid.Log.Filename = @"C:\Temp\log.txt";

        // Subscribe to event.
        valid.Verified += new VerifiedEventHandler(valid_Verified);

        // In this sample, we'll build DataTable manually from a string array.
        string[] emails = new string[10];
        for (int i = 0; i < emails.Length; i++)
            // Make,, ...,
            emails[i] = string.Format("user{0}@domain{0}.com", i.ToString());

        // In real apps, you'll get data from database. For now, populate data from
        // string array by putting all the data into a table with one column "email".
        DataTable data = valid.ArrayToDataTable(emails);

        // Enable as many threads as possible.
        valid.MaxThreadCount = -1;

        using (sw = new StreamWriter(@"C:\Temp\report.txt"))
            // Run the verification in multi-threaded mode.
            valid.Verify(data, "email");
See Also