Begins an asynchronous request for downloading the entire or partial messages in the specified range from the server.
An IAsyncResult that references the asynchronous downloading the message.
This method is an asynchronous version of DownloadMessageHeaders.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
This sample asynchronously downloads headers of all the messages in the inbox. Then, it displays the following information about each message:
[C#] using System; using MailBee; using MailBee.Pop3Mail; using MailBee.Mime; class Sample { // MessageDataChunkReceived event handler. private static void OnMessageDataChunkReceived(object sender, Pop3MessageDataChunkReceivedEventArgs e) { Console.WriteLine(e.BytesJustReceived + " bytes of the message #" + e.MessageNumber + " received"); } // The actual code. static void Main(string[] args) { Pop3 pop = new Pop3(); pop.Connect("pop.somehost.com"); pop.Login("jdoe", "secret"); // Subscribe to MessageDataChunkReceived event. pop.MessageDataChunkReceived += new Pop3MessageDataChunkReceivedEventHandler(OnMessageDataChunkReceived); // Initiate an asynchronous download attempt. pop.BeginDownloadMessages(1, -1, 0, null, null); // Simulate some lengthy work here. At the same time, // the messages are downloaded on another thread. System.Threading.Thread.Sleep(3000); // End the messages download operation and return MailMessageCollection object. // If the operation is still in progress at the moment when // this method starts, the method will wait until the operation completion. MailMessageCollection msgs = pop.EndDownloadMessages(); foreach (MailMessage msg in msgs) { Console.WriteLine("Message #" + msg.IndexOnServer + ": the length of the entire message is " + msg.SizeOnServer + " bytes, the length of the downloaded header is " + msg.Size + " bytes."); } // Disconnect from the server. pop.Disconnect(); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.Pop3Mail Imports MailBee.Mime Class Sample ' MessageDataChunkReceived event handler. Private Shared Sub OnMessageDataChunkReceived(ByVal sender As Object, _ ByVal e As Pop3MessageDataChunkReceivedEventArgs) Console.WriteLine(e.BytesJustReceived & " bytes of the message #" & _ e.MessageNumber & " received") End Sub ' The actual code Shared Sub Main(ByVal args As String()) Dim pop As Pop3 pop.Connect("pop.somehost.com") pop.Login("jdoe", "secret") ' Subscribe to MessageDataChunkReceived event. AddHandler pop.MessageDataChunkReceived, AddressOf OnMessageDataChunkReceived ' Initiate an asynchronous download attempt. pop.BeginDownloadMessages(1, -1, 0, Nothing, Nothing) ' Simulate some lengthy work here. At the same time, ' the messages are downloaded on another thread. System.Threading.Thread.Sleep(3000) ' End the messages download operation and return MailMessageCollection object. ' If the operation is still in progress at the moment when ' this method starts, the method will wait until the operation completion. Dim msgs As MailMessageCollection msgs = pop.EndDownloadMessages() For Each msg As MailMessage In msgs Console.WriteLine("Message #" + msg.IndexOnServer & _ ": the length of the entire message is " & msg.SizeOnServer & _ " bytes, the length of the downloaded header is " & msg.Size & " bytes.") Next ' Disconnect from the server. pop.Disconnect() End Sub End Class
Pop3 Class | MailBee.Pop3Mail Namespace | DownloadEntireMessages | DownloadMessageHeaders