MailBee.NET Objects 3.1

Imap.DownloadEntireMessages Method 

Completely downloads the specified messages from the server.

public MailMessageCollection DownloadEntireMessages(
   string messageIndexSet,
   bool indexIsUid
);

Parameters

messageIndexSet
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
indexIsUid
If true, messageIndexSet is treated as a sequence of UIDs; otherwise, as a sequence of ordinal message numbers.

Return Value

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

Remarks

To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes topic.

This method will download all the messages in a single network operation, which greatly increases performance and reduces network traffic.

Note   To track downloading messages, EnvelopeDownloaded event should be used. There is no MessageDownloaded event since mail messages are actually downloaded within envelopes. Once an envelope is downloaded, the mail message data is extracted from it. Generally speaking, DownloadEntireMessages is a kind of overload of DownloadEnvelopes method.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This console sample completely downloads the last 10 messages from the inbox, and displays the number of attachments for each downloaded message. EnvelopeDownloaded event is used to track the download progress.

[C#]
using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

class Sample
{
    // EnvelopeDownloaded event handler.
    private static void OnEnvelopeDownloaded(object sender,
        ImapEnvelopeDownloadedEventArgs e)
    {
        Console.WriteLine("Message #" + e.MessageNumber + " downloaded");
    }

    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Connect("mail.domain.com");
        imp.Login("jdoe", "secret");
        imp.SelectFolder("INBOX");

        // Subscribe to the EnvelopeDownloaded event.
        imp.EnvelopeDownloaded +=
            new ImapEnvelopeDownloadedEventHandler(OnEnvelopeDownloaded);

        // Download the last 10 messages. Note: this sample does not check
        // if there are less than 10 messages in the inbox. See sample code
        // in DownloadEnvelopes(string, bool) overload for more information.
        MailMessageCollection msgs = imp.DownloadEntireMessages(
            (imp.MessageCount - 9).ToString() + ":*", false);

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

        // Disconnect from the server.
        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail
Imports MailBee.Mime

Module Sample
    ' EnvelopeDownloaded event handler.
    Private Sub OnEnvelopeDownloaded(ByVal sender As Object, _
        ByVal e As ImapEnvelopeDownloadedEventArgs)

        Console.WriteLine("Message #" & e.MessageNumber & " downloaded")
    End Sub

    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Connect to the server, login and select inbox.
        imp.Connect("mail.domain.com")
        imp.Login("jdoe", "secret")
        imp.SelectFolder("INBOX")

        ' Subscribe to the EnvelopeDownloaded event.
        AddHandler imp.EnvelopeDownloaded, AddressOf OnEnvelopeDownloaded

        ' Download the last 10 messages. Note: this sample does not check
        ' if there are less than 10 messages in the inbox. See sample code
        ' in DownloadEnvelopes(string, bool) overload for more information.
        Dim msgs As MailMessageCollection = _
            imp.DownloadEntireMessages((imp.MessageCount - 9).ToString() & ":*", False)

        ' Display some information about downloaded messages.
        For Each msg As MailMessage In msgs
            Console.WriteLine("Message #" & msg.IndexOnServer & " contains " & _
                 msg.Attachments.Count & " attachment(s)")
        Next

        ' Disconnect from the server.
        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace