Home > Uncategorized > Validating e-mail addresses in an IList interface Synchronously

Validating e-mail addresses in an IList interface Synchronously

July 18, 2010

ComponentSoft UltimateEmailValidator provides a number of convenient ways to verify email addresses, one of them is verifying email addresses in an IList interface.

The example below will demonstrate how to use ValidateEmails method to verify email addresses in an IList interface:

Validating a single e-mail address

  1. Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
    C# Copy Code
    using ComponentSoft.Net;
    VB.NET Copy Code
    Imports ComponentSoft.Net
  2. Create a new instance of the EmailValidator class.
    C# Copy Code
    // Create a new instance of the EmailValidator class.
    EmailValidator client = new EmailValidator();
    VB.NET Copy Code
    ‘ Create a new instance of the EmailValidator class.
    Dim client As New EmailValidator()
  3. Now pass the list containing e-mail addresses you want to validate to the ValidateEmails method. The code looks similar to the following:
    C# Copy Code
    em.MessageLogging += em_MessageLogging;
    em.EmailValidated += em_EmailValidationCompleted;
    try
    {
    string[] list = new string[3] { test1@testdomain.com, test2@testdomain.com, test3@testdomain.com” };
    em.ValidateEmails(list);
    }
    catch (EmailValidatorException exc2)
    {
    Console.WriteLine(
    “EmailValidatorException: “ + exc2.Message);
    }
    VB.NET Copy Code
    AddHandler em.MessageLogging, AddressOf em_MessageLogging
    AddHandler em.EmailValidated, AddressOf em_EmailValidationCompleted
    Try
    Dim list() As String = {“test1@testdomain.com”, “test2@testdomain.com”, “test3@testdomain.com”}
    em.ValidateEmails(list)
    Catch exc2 As EmailValidatorException
    Console.WriteLine(“EmailValidatorException: “ & exc2.Message)
    End Try

Final example code

C# Copy Code
static void Main()
{
// Create a new instance of the EmailValidator class.
EmailValidator em = new EmailValidator();
em.MessageLogging += em_MessageLogging;
em.EmailValidated += em_EmailValidationCompleted;
try
{
string[] list = new string[3] { test1@testdomain.com, test2@testdomain.com, test3@testdomain.com” };
em.ValidateEmails(list);
}
catch (EmailValidatorException exc2)
{
Console.WriteLine(
“EmailValidatorException: “ + exc2.Message);
}
}
static void em_EmailValidationCompleted(object sender, EmailValidatedEventArgs e)
{
if (e.ValidatedLevel == ValidationLevel.Success)
Console.WriteLine(e.EmailAddress +
” validation done”);
else
Console.WriteLine(e.EmailAddress + ” validation failed at “ + e.ValidatedLevel);
}
static void em_MessageLogging(object sender, EmailValidatorLogEventArgs e)
{
Console.Write(e.SmtpTranscript);
}
VB.NET Copy Code
Sub Main()
‘ Create a new instance of the EmailValidator class.
Dim em As New EmailValidator()
AddHandler em.MessageLogging, AddressOf em_MessageLogging
AddHandler em.EmailValidated, AddressOf em_EmailValidationCompleted
Try
Dim list() As String = {“test1@testdomain.com”, “test2@testdomain.com”, “test3@testdomain.com”}
em.ValidateEmails(list)
Catch exc2 As EmailValidatorException
Console.WriteLine(“EmailValidatorException: “ & exc2.Message)
End Try
End Sub
Private Sub em_EmailValidationCompleted(ByVal sender As Object, ByVal e As EmailValidatedEventArgs)
If e.ValidatedLevel = ValidationLevel.Success Then
Console.WriteLine(e.EmailAddress & ” validation done”)
Else
Console.WriteLine(e.EmailAddress & ” validation failed at “ & e.ValidatedLevel)
End If
End Sub
Private Sub em_MessageLogging(ByVal sender As Object, ByVal e As EmailValidatorLogEventArgs)
Console.Write(e.SmtpTranscript)
End Sub
Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.