ComponentPro UltimateMail

      DownloadMailMessageAsync(Int32) Method

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Asynchronously completely downloads the specified message from the server and loads it into an instance of the MailMessage class.

      Syntax

      public ExtendedAsyncResult<MailMessage> DownloadMailMessageAsync(
         int messageInboxIndex
      )

      Parameters

      messageInboxIndex
      The ordinal position of the message in the inbox. It must be in the range from 1 to MessageCount.

      Return Value

      An object that references the asynchronous operation.

      Examples

      Shows how to connect to a POP3 server and download a message asynchronously.

      using System;
      using System.ComponentModel;
      using ComponentPro;
      using ComponentPro.Net.Mail;
      
      ...
      
      // Create a new instance of the Pop3 class.
      Pop3 client = new Pop3();
      
      // Connect to the server.
      client.Connect("myserver");
      
      // Or you can specify the POP3 port with 
      // client.Connect("myserver", 110); 
       
      // Login to the server.
      client.Authenticate("user", "password");
      
      // ... 
       
      // Download a mail message with sequence number 1.
      MailMessage msg = await client.DownloadMailMessageAsync(1);
      
      // ...
      Console.WriteLine("Message downloaded successfully.");
      Console.WriteLine("Message ID: {0}, Subject: {1}", msg.MessageIdentifier, msg.Subject);
      
      // Disconnect.
      client.Disconnect();

      Shows how to connect to a POP3 server and download a message asynchronously.

      using System;
      using System.ComponentModel;
      using ComponentPro;
      using ComponentPro.Net.Mail;
      
      ...
      
      public void DoDownloadMailMessageAsync()
      {
          // Create a new instance of the Pop3 class. 
          Pop3 client = new Pop3();
      
          // Connect to the server. 
          client.Connect("myserver");
      
          // Or you can specify the POP3 port with 
          // client.Connect("myserver", 110); 
       
          // Login to the server. 
          client.Authenticate("user", "password");
      
          // ... 
       
          // Register an event handler. 
          client.DownloadMailMessageCompleted += client_DownloadMailMessageCompleted;
      
          // Download a mail message with sequence number 1. 
          client.DownloadMailMessageAsync(1);
      
          // ... 
       
          // Disconnect. 
          client.Disconnect();
      }
      
      void client_DownloadMailMessageCompleted(object sender, ExtendedAsyncCompletedEventArgs<MailMessage> e)
      {
          // Pop3 client = (Pop3)sender; 
          if (e.Error != null)
              Console.WriteLine("Error: " + e.Error.ToString());
          else 
          {
              MailMessage msg = e.Result;
      
              Console.WriteLine("Message downloaded successfully.");
              Console.WriteLine("Message ID: {0}, Subject: {1}", msg.MessageIdentifier, msg.Subject);
          }
      }

      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