ImapDownloadEntireMessages Method |
Namespace: MailBee.ImapMail
public MailMessageCollection DownloadEntireMessages( string messageIndexSet, bool indexIsUid )
Exception | Condition |
---|---|
MailBeeException | An error occurred and ThrowExceptions is true. |
To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes(String, Boolean) topic.
This method will download all the messages in a single network operation, which greatly increases performance and reduces network traffic.
To make messages SEEN upon downloading, change SetSeenForEntireMessages property value to true before calling this method.
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(String, Boolean) is a kind of overload of DownloadEnvelopes(String, Boolean, EnvelopeParts, Int32, String, String) method. |
For advanced purposes, use DownloadEnvelopes(String, Boolean, EnvelopeParts, Int32, String, String). With IMAP envelopes, you can get extra flags, and more.
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(); } }