ComponentPro UltimateBounceInspector

      Cancelling an operation

      Language Filter: AllSend comments on this topic to ComponentPro

      To abort any mail message process in progress you can call the Cancel method of the BounceInspector class.

      The following steps show how to cancel an operation using the Cancel method.

      Cancelling an operation

      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:
        using System;
        using ComponentPro.Net.Mail;
        
      2. Create a new instance of the BounceInspector class.
        // Create a new instance of the BounceInspector class.
        BounceInspector inspector = new BounceInspector();
        
        // Register an event handler.
        inspector.Processed += inspector_Processed;
        
      3. Now pass the path of the directory containing EML files to scan to the ProcessMessages method. The code looks similar to the following:
        // Process all EML files in directory 'c:\\temp'.
        BounceResultCollection result = inspector.ProcessMessages("c:\\temp");
        
        // Display processed emails. 
        foreach (BounceResult r in result)
        {
            // If this message was identified as a bounced email message. 
            if (r.Identified)
            {
                // Print out the result 
                Console.Write("FileName: {0}\nSubject: {1}\nAddress: {2}\n" +
                              "Bounce Category: {3}\n" +
                              "Bounce Type: {4}\nDeleted: {5}\n" +
                              "DSN Action: {6}\n" +
                              "DSN Diagnostic Code: {7}\n\n",
                              System.IO.Path.GetFileName(r.FilePath),
                              r.MailMessage.Subject,
                              r.Addresses[0],
                              r.BounceCategory.Name,
                              r.BounceType.Name,
                              r.FileDeleted,
                              r.Dsn.Action,
                              r.Dsn.DiagnosticCode);
            }
        }
        

      Final example code

      using System;
      using ComponentPro.Net.Mail;
      
      ...
      
      static void Main()
      {
          // Create a new instance of the BounceInspector class. 
          BounceInspector inspector = new BounceInspector();
      
          // Register an event handler. 
          inspector.Processed += inspector_Processed;
      
          // Process all EML files in directory 'c:\\temp'. 
          BounceResultCollection result = inspector.ProcessMessages("c:\\temp");
      
          // Display processed emails. 
          foreach (BounceResult r in result)
          {
              // If this message was identified as a bounced email message. 
              if (r.Identified)
              {
                  // Print out the result 
                  Console.Write("FileName: {0}\nSubject: {1}\nAddress: {2}\n" +
                                "Bounce Category: {3}\n" +
                                "Bounce Type: {4}\nDeleted: {5}\n" +
                                "DSN Action: {6}\n" +
                                "DSN Diagnostic Code: {7}\n\n",
                                System.IO.Path.GetFileName(r.FilePath),
                                r.MailMessage.Subject,
                                r.Addresses[0],
                                r.BounceCategory.Name,
                                r.BounceType.Name,
                                r.FileDeleted,
                                r.Dsn.Action,
                                r.Dsn.DiagnosticCode);
              }
          }
      
          Console.WriteLine("{0} bounced message found", result.BounceCount);
      }
      
      private static int _count;
      static void inspector_Processed(object sender, ProcessedEventArgs e)
      {
          _count++;
          // Only process 10 mail messages. 
          if (_count == 10)
          {
              ((BounceInspector)sender).Cancel();
          }
      }