Pop3DownloadMessageHeaders Method
Downloads headers of all messages in the inbox on the server.

Namespace: MailBee.Pop3Mail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public MailMessageCollection DownloadMessageHeaders()

Return Value

Type: MailMessageCollection
On success, a MailMessageCollection object containing the downloaded message headers; otherwise, a null reference (Nothing in Visual Basic).
MailBeeExceptionAn error occurred and ThrowExceptions is true.
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.
This sample downloads headers of all the messages in the mailbox, and displays the following information for each message:
  • The display name of the sender (or the e-mail address if the display name is not available)
  • The display names of the recipients (or the e-mail address when the particular display name is not available)
The message information is displayed in descending order (from newer messages to older ones).
// 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.Login("jdoe", "secret");

// Download headers of all the messages in the inbox.
MailMessageCollection msgs = pop.DownloadMessageHeaders();

// Reverse the order of the elements to make newer messages appear first in the collection.

foreach (MailMessage msg in msgs)
    // Get the sender.
    string sender = msg.From.DisplayName;
    if (sender == string.Empty)
        sender = msg.From.Email;

    // Get the list of recipients.
    string recipients = string.Empty;
    foreach (EmailAddress address in msg.GetAllRecipients())
        string recipient = address.DisplayName;
        if (recipient == string.Empty)
            recipient = address.Email; 

        if (recipients == string.Empty)
            recipients += recipient;
            recipients += ", " + recipient;

    Console.WriteLine("Message #" + msg.IndexOnServer + " was originally sent by " + sender + " to " + recipients);

See Also