ComponentPro UltimateBounceInspector

      UnsubscribeAsync(String) Method

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Asynchronously unsubscribes the previously subscribed folder (using the Subscribe method) of the IMAP4 account, removing it from the list of active folders that appear in the folder listings with subscribedOnly parameter set to true.

      Syntax

      public ExtendedAsyncResult UnsubscribeAsync(
         string folder
      )

      Parameters

      folder
      The full name of the folder to be unsubscribed.

      Return Value

      An object that references the asynchronous operation.

      Examples

      Connect to an IMAP server and subscribe/unsubscribe a folder asynchronously (Task-based asynchronous approach).

      using System;
      using System.ComponentModel;
      using System.Text;
      using ComponentPro;
      using ComponentPro.Net.Mail;
      
      ...
      
      // Create a new instance of the Imap class.
      Imap client = new Imap();
      
      // Connect to the server. 
      await client.ConnectAsync("myserver");
      
      // Or you can specify the IMAP port with 
      // client.Connect("myserver", 143); 
       
      // Login to the server. 
      await client.AuthenticateAsync("user", "password");
      
      // ... 
       
      // Select 'INBOX' mailbox.
      client.Select("INBOX");
      
      // ... 
       
      await client.SubscribeAsync("my folder");
      
      Console.WriteLine("Folder unsubscribed.");
      
      StringBuilder sb = new StringBuilder("Subscribed Folders: ");
      
      FolderCollection list = await client.ListFoldersAsync("", true);
      for (int i = 0; i < list.Count; i++)
      {
          sb.AppendFormat("{0} - {1}\r\n", i + 1, list[i].Name);
      }
      
      // ... 
       
      // Later we can unsubscribe the folder. 
      await client.UnsubscribeAsync("my folder");
      
      Console.WriteLine("Folder unsubscribed.");
      
      // Disconnect.
      client.Disconnect();

      Connect to an IMAP server and subscribe/unsubscribe a folder asynchronously (Event-based asynchronous approach).

      using System;
      using System.ComponentModel;
      using System.Text;
      using ComponentPro;
      using ComponentPro.Net.Mail;
      
      ...
      
      public void DoSubscribeAsync()
      {
          // Create a new instance of the Imap class. 
          Imap client = new Imap();
      
          // Connect to the server. 
          client.Connect("myserver");
      
          // Or you can specify the IMAP port with 
          // client.Connect("myserver", 143); 
       
          // Login to the server. 
          client.Authenticate("user", "password");
      
          // ... 
       
          // Select 'INBOX' mailbox. 
          client.Select("INBOX");
      
          // ... 
       
          client.SubscribeCompleted += client_SubscribeCompleted;
          client.UnsubscribeCompleted += new AsyncCompletedEventHandler(client_UnsubscribeCompleted);
      
          client.SubscribeAsync("my folder");
      
          // ... 
       
          // Later we can unsubscribe the folder. 
          client.UnsubscribeAsync("my folder");
      
          // Disconnect. 
          client.Disconnect();
      }
      
      void client_UnsubscribeCompleted(object sender, AsyncCompletedEventArgs e)
      {
          // Imap client = (Imap)sender; 
          if (e.Error != null)
              Console.WriteLine("Error: " + e.Error.ToString());
          else 
          {
              Console.WriteLine("Folder unsubscribed.");
          }
      }
      
      void client_SubscribeCompleted(object sender, AsyncCompletedEventArgs e)
      {
          Imap client = (Imap)sender;
          if (e.Error != null)
              Console.WriteLine("Error: " + e.Error.ToString());
          else 
          {
              StringBuilder sb = new StringBuilder("Subscribed Folders: ");
      
              FolderCollection list = client.ListFolders("", true);
              for (int i = 0; i < list.Count; i++)
              {
                  sb.AppendFormat("{0} - {1}\r\n", i + 1, list[i].Name);
              }
          }
      }

      Framework

      .NET Compact Framework.NET Compact Framework

      Supported version: 2.0, 3.5, and 3.9
      Assembly: ComponentPro.Mail.CF (in ComponentPro.Mail.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.Mail (in ComponentPro.Mail.dll)

      See Also