ComponentPro UltimateMail

      DownloadMessageHeaders Method

      See AlsoMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Downloads the headers of a message with the specified inbox index from the server and writes its data into a supplied stream.

      Syntax

      public long DownloadMessageHeaders(
         int messageInboxIndex, 
         Stream output
      )

      Parameters

      messageInboxIndex
      The ordinal position of the message in the inbox. It must be in the range from 1 to MessageCount.
      output
      Stream that will receive the message.

      Return Value

      On success, the length of the message in bytes is returned.

      Examples

      Shows how to connect to a POP3 server and download headers of a message.

      using System;
      using System.IO;
      using ComponentPro.Net;
      using ComponentPro.Net.Mail;
      
      ...
      
      const string serverName = "myserver";
      const string user = "name@domain.com";
      const string password = "password";
      const int port = 995;
      const SslSecurityMode securityMode = SslSecurityMode.Implicit;
      
      Pop3 client = new Pop3();
      try
      {
          Console.WriteLine("Connecting POP3 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);
      
          // Get mailbox info. 
          Pop3MailboxStat info = client.GetMailboxStat();
      
          // Show the number of messages in the selected folder. 
          Console.WriteLine("{0} messages found.", info.MessageCount);
      
      
          // Get the message list. 
          Console.WriteLine("Getting message list...");
          Pop3MessageCollection list = client.ListMessages(Pop3EnvelopeParts.FullHeaders);
      
          Pop3Message message;
          for (int i = 0; i < list.Count; i++)
          {
              message = list[i];
      
              // Print out message uniqueid and sequence id     
              Console.WriteLine("UniqueId: {0}, Sequence Num: {1}", message.UniqueId, message.MessageInboxIndex);
              Console.WriteLine("From: {0}, To: {1}, Subject: '{2}'", message.From, message.To, message.Subject);
              Console.WriteLine();
          }
      
      
      
          // Get the message list. 
          Console.WriteLine("Getting message list...");
          list = client.ListMessages(Pop3EnvelopeParts.MessageInboxIndex);
      
          for (int i = 0; i < list.Count; i++)
          {
              message = list[i];
      
              // Download message headers to a stream. 
              Stream s = new MemoryStream();
              client.DownloadMessageHeaders(message.MessageInboxIndex, s);
      
              // Load message from the Stream object. 
              MailMessage msg = new MailMessage(s);
      
              // Print out message uniqueid and sequence id     
              Console.WriteLine("Inbox Index: {0}", message.MessageInboxIndex);
              Console.WriteLine("From: {0}, To: {1}, Subject: '{2}'", msg.From, msg.To, msg.Subject);
              Console.WriteLine();
          }
      
      
          // Disconnect. 
          Console.WriteLine("Disconnecting...");
          client.Disconnect();
      
      }
      catch (Pop3Exception pop3Exc)
      {
          Console.WriteLine(string.Format("An POP3 error occurred: {0}, ErrorStatus: {1}", pop3Exc.Message, pop3Exc.Status));
      }
      catch (Exception exc)
      {
          Console.WriteLine(string.Format("An error occurred: {0}", exc.Message));
      }

      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)

      Xamarin AndroidXamarin Android

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

      Xamarin MacXamarin Mac

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

      Xamarin iOSXamarin iOS

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

      See Also