ComponentPro UltimateEmailValidator

      Handling Exceptions

      Language Filter: AllSend comments on this topic to ComponentPro

      Handling Exceptions in UltimateEmailValidator

      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:

      using System;
      using ComponentPro.Net;
      
      ...
      
      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@componentpro.com;support@componentpro.com;contact@componentpro.com");
          }
          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);
      }