MailBee.NET Objects 3.1

Pop3.DownloadMessageHeaders Method (Int32, Int32)

Downloads the header of each message in the specified range from the server.

public MailMessageCollection DownloadMessageHeaders(
   int startIndex,
   int count
);

Parameters

startIndex
The ordinal position (in the inbox) of the first message in the range to be downloaded.
count
Number of messages to be downloaded, or -1 to indicate that all messages in the range startIndex to InboxMessageCount must be downloaded.

Return Value

On success, a MailMessageCollection object containing the downloaded message headers; otherwise, a null reference (Nothing in Visual Basic).

Remarks

If the POP3 server supports pipelining, this method will download all the messages in a single network operation, which greatly increases performance and reduces network traffic.

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

This sample downloads headers of the last 10 messages in the mailbox, and displays the following information for each message:

The message information is displayed in descending order (from newer messages to older ones).
[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Pop3Mail;
using MailBee.Mime;

// The actual code (put it into a method of your class).
Pop3 pop = new Pop3();
pop.Connect("mail.domain.com");
pop.Login("jdoe", "secret");

// Download headers of the last 10 messages.
MailMessageCollection msgs = pop.DownloadMessageHeaders(pop.InboxMessageCount - 9, 10);

// Reverse the order of the elements to make newer messages appear first in the collection.
msgs.Reverse();

// Display Date, DateReceived, and Subject.
foreach (MailMessage msg in msgs)
{
    Console.WriteLine("Message #" + msg.IndexOnServer + ", created at " + msg.Date + " and received at " + msg.DateReceived + ", has Subject: " + msg.Subject);
}

pop.Disconnect();
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Pop3Mail
Imports MailBee.Mime

' The actual code (put it into a method of your class).
Dim pop As New Pop3
pop.Connect("mail.domain.com")
pop.Login("jdoe", "secret")

' Download headers of the last 10 messages.
Dim msgs As MailMessageCollection = pop.DownloadMessageHeaders(pop.InboxMessageCount - 9, 10)

' Reverse the order of the elements to make newer messages appear first in the collection.
msgs.Reverse()

' Display Date, DateReceived, and Subject.
For Each msg As MailMessage In msgs
    Console.WriteLine("Message #" & msg.IndexOnServer & ", created at " & msg.Date & " and received at " & msg.DateReceived & ", has Subject: " & msg.Subject)
Next

pop.Disconnect()

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | Pop3.DownloadMessageHeaders Overload List