Home > Uncategorized > ComponentSoft UltimateEmailValidator – Handling Exceptions

ComponentSoft UltimateEmailValidator – Handling Exceptions

When calling methods in the EmailValidator class you should consider to catch the exceptions listed below:

  1. EmailValidatorException

Source Code

Example below shows how to handle this exception in ComponentSoft Email Validator:

C# Copy Code
static void Main()
{
EmailValidator em =
new EmailValidator();
em.MessageLogging += em_MessageLogging;
em.EmailValidated += em_EmailValidationCompleted;
em.EmailValidating += em_EmailValidating;
em.Progress += em_Progress;
try
{
em.Validate(test@somedomain.com);
em.ValidateEmails(
sales@componentsoft.net;support@componentsoft.net;info@componentsoft.net);
}
catch (EmailValidatorException exc2)
{
Console.WriteLine(
“EmailValidatorException: “ + exc2.Message);
}
}
static void em_Progress(object sender, EmailValidatorProgressEventArgs e)
{
if (e.EmailAddress != null)
if (e.Passed)
Console.WriteLine(
”    Passed: “ + e.Level.ToString());
else
Console.WriteLine(”    Failed: “ + e.Level.ToString());
if (e.TotalEmails != -1)
Console.WriteLine(
string.Format(“Progress: {0}%”, e.ProgressPercentage));
}
static void em_EmailValidating(object sender, EmailValidatingEventArgs e)
{
Console.WriteLine(
string.Format(“Start validating email ‘{0}’”, e.EmailAddress));
}
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()
Dim em As New EmailValidator()
AddHandler em.MessageLogging, AddressOf em_MessageLogging
AddHandler em.EmailValidated, AddressOf em_EmailValidationCompleted
AddHandler em.EmailValidating, AddressOf em_EmailValidating
AddHandler em.Progress, AddressOf em_Progress
Try
em.Validate(“test@somedomain.com”)
em.ValidateEmails(“sales@componentsoft.net;support@componentsoft.net;info@componentsoft.net”)
Catch exc2 As EmailValidatorException
Console.WriteLine(“EmailValidatorException: “ & exc2.Message)
End Try
End Sub
Private Sub em_Progress(ByVal sender As Object, ByVal e As EmailValidatorProgressEventArgs)
If e.EmailAddress IsNot Nothing Then
If e.Passed Then
Console.WriteLine(” Passed: “ & e.Level.ToString())
Else
Console.WriteLine(” Failed: “ & e.Level.ToString())
End If
End If
If e.TotalEmails <> -1 Then
Console.WriteLine(String.Format(“Progress: {0}%”, e.ProgressPercentage))
End If
End Sub
Private Sub em_EmailValidating(ByVal sender As Object, ByVal e As EmailValidatingEventArgs)
Console.WriteLine(String.Format(“Start validating email ‘{0}’”, e.EmailAddress))
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

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.