Pop3DownloadEntireMessages Method (Int32, Int32)
Completely downloads the messages in the specified range from the server.

Namespace: MailBee.Pop3Mail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
public MailMessageCollection DownloadEntireMessages(
	int startIndex,
	int count


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

Return Value

Type: MailMessageCollection
On success, a MailMessageCollection containing the downloaded messages; 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.

Note Note
As this method downloads multiple e-mails at once, you must have plenty of memory to have such operation done. In case of out-of-memory issues, reduce count or download large emails individually.

You can use GetMessageSizes method to learn the sizes of all e-mails in the inbox without downloading them. For instance, if you found that you have 10 small e-mails less than 10MB total, then a large 100MB e-mail, then many small e-mails 500MB total, you can first download 10 small emails with a single call of DownloadEntireMessages(Int32, Int32) overload, process them, then download a large e-mail with DownloadEntireMessage(Int32) method, process it, and then use DownloadEntireMessages(Int32, Int32) overload again several times to get e-mails downloaded in approx. 100MB groups. This way, you won't need to download each and every e-mail one-by-one (which would defeat the idea of using pipelining) and still won't use too much memory. Small e-mails will be downloaded in a batch while large ones will get downloaded on their own.

This sample completely downloads the last 10 messages from the inbox, and displays the number of attachments for each downloaded message. MessageDownloaded event is used to track the download progress. The sample is written for a console application.
using System;
using MailBee;
using MailBee.Pop3Mail;
using MailBee.Mime;

class Sample
    // MessageDownloaded event handler.
    private static void OnMessageDownloaded(object sender, Pop3MessageDownloadedEventArgs e)
        Console.WriteLine("Message #" + e.MessageNumber + " downloaded");

    // The actual code.
    static void Main(string[] args)
        Pop3 pop = new Pop3();
        pop.Login("jdoe", "secret");

        // Subscribe to the MessageDownloaded event.
        pop.MessageDownloaded += new Pop3MessageDownloadedEventHandler(OnMessageDownloaded);

        // Download the messages.
        MailMessageCollection msgs = pop.DownloadEntireMessages(pop.InboxMessageCount - 9, 10);

        // Display some information about downloaded messages.
        foreach (MailMessage msg in msgs)
            Console.WriteLine("Message #" + msg.IndexOnServer +
                " contains " + msg.Attachments.Count + " attachment(s)");

See Also