ComponentPro UltimateBounceInspector

      DownloadingMessageEventArgs Class

      See AlsoMembersMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Provides data for the DownloadingMessage Event.

      Syntax

      public class DownloadingMessageEventArgs : AsyncEventArgs

      Examples

      Shows how to handle the DownloadingMessage event when processing messages downloaded from an IMAP server.

      using System;
      using System.Windows.Forms;
      using ComponentPro.Net;
      using ComponentPro.Net.Mail;
      
      ...
      
      static void Main()
      {
          // IMAP server information. 
          const string serverName = "myserver";
          const string user = "name@domain.com";
          const string password = "mytestpassword";
          const int port = 993;
          const SslSecurityMode securityMode = SslSecurityMode.Implicit;
      
          // Create a new instance of the Imap class. 
          Imap client = new Imap();
          try 
          {
              Console.WriteLine("Connecting IMAP server: {0}:{1}...", serverName, port);
              // Connect to the server. 
              client.Connect(serverName, port, securityMode);
      
              // Login to the server. 
              Console.WriteLine("Logging in as {0}...", user);
              client.Authenticate(user, password);
      
              // Initialize BounceInspector. 
              BounceInspector inspector = new BounceInspector();
              inspector.AllowInboxDelete = false; // true if you want BounceInspector automatically delete all hard bounces. 
       
              // Handle events. 
              inspector.Processing += inspector_Processing;
              inspector.Processed += inspector_Processed;
              inspector.DownloadingMessage += inspector_DownloadingMessage;
      
              // Download messages from IMAP 'Inbox' folder to 'c:\test' and process them. 
              BounceResultCollection result = inspector.ProcessMessages(client, "Inbox", "c:\\test");
              // Download messages from IMAP 'Inbox' folder to memory stream and process them. 
              //BounceResultCollection result = inspector.ProcessMessages(client, "Inbox"); 
       
              // 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}\nBounce Category: {3}\nBounce Type: {4}\nDeleted: {5}\nDSN Action: {6}\nDSN 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);
      
              // Disconnect. 
              Console.WriteLine("Disconnecting...");
              client.Disconnect();
      
          }
          catch (ImapException imapExc)
          {
              MessageBox.Show(string.Format("An IMAP error occurred: {0}, ErrorStatus: {1}", imapExc.Message, imapExc.Status));
          }
          catch (Exception exc)
          {
              MessageBox.Show(string.Format("An error occurred: {0}", exc.Message));
          }
      }
      
      static void inspector_Processing(object sender, ProcessingEventArgs e)
      {
          // Skip all messages containing "Test" in subject. 
          if (e.MailMessage.Subject.IndexOf("Test") != -1)
              e.Skip = true;
      }
      
      static int id = 0;            
      
      /// <summary> 
      /// Handles the BounceInspector's DownloadingMessages event. 
      /// </summary> 
      /// <param name="sender">The BounceInspector object.</param> 
      /// <param name="e">The event arguments.</param> 
      static void inspector_DownloadingMessage(object sender, DownloadingMessageEventArgs e)
      {
          if (e.FileExists)
              // Skip if message containing "Cxj89" already exists. 
              if (e.ImapMessage.UniqueId.IndexOf("Cxj89") != -1)
              {
                  e.Skip = true;
              }
              // Otherwise rename destination file name. 
              else 
              {
                  e.FileName = "tmp" + id;
                  id++;
                  // You can also set e.DirectoryName to another destination folder. 
                  // e.DirectoryName = "temp"; 
              }
      }
      
      /// <summary> 
      /// Handles the BounceInspector's Processed event. 
      /// </summary> 
      /// <param name="sender">The BounceInspector object.</param> 
      /// <param name="e">The event arguments.</param> 
      static void inspector_Processed(object sender, ProcessedEventArgs e)
      {
          Console.WriteLine("Processed mail with subject '{0}'...", e.MailMessage.Subject);
      }

      Inheritance Hierarchy

               ComponentPro.Net.Mail.ComponentPro.Net.Mail.DownloadingMessageEventArgs

      Framework

      .NET Compact Framework.NET Compact Framework

      Supported version: 2.0, 3.5, and 3.9
      Assembly: ComponentPro.BounceInspector.CF (in ComponentPro.BounceInspector.CF.dll)

      .NET Framework.NET Framework

      Supported version: 2.0, 3.0, 3.5, 4.0, 4.5.x, 4.6.x and later
      Assembly: ComponentPro.BounceInspector (in ComponentPro.BounceInspector.dll)

      Xamarin AndroidXamarin Android

      Supported version: 2.3 and later
      Assembly: ComponentPro.BounceInspector.Android (in ComponentPro.BounceInspector.Android.dll)

      Xamarin MacXamarin Mac

      Supported version: 2.0.x and later
      Assembly: ComponentPro.BounceInspector.Mac (in ComponentPro.BounceInspector.Mac.dll)

      Xamarin iOSXamarin iOS

      Supported version: 5.1.x and later
      Assembly: ComponentPro.BounceInspector.iOS (in ComponentPro.BounceInspector.iOS.dll)

      See Also