Downloads the header and the specified number of body lines of each message in the specified range from the server.
On success, a MailMessageCollection object containing the downloaded partial messages; otherwise, a null reference (Nothing in Visual Basic).
When bodyLineCount is 0, only the message header is downloaded. When bodyLineCount is -1, this method is equivalent to DownloadEntireMessage method.
Setting bodyLineCount to a positive value allows the developer to implement message body preview feature. In this case, it's recommended to set bodyLineCount >= 20 since the first 5-15 lines of the message source body are often filled with the special information and do not contain the actual body text.
If bodyLineCount is set to a certain value (such as 100), small messages having less than 100 lines in the message source body will be downloaded completely. Larger messages will be parsed partially. For instance, if 100 body lines of the message have been received, and the message contains an attachment which starts at 80-th line and ends at 150-th line of the message source body (so it has not fitted in the 100 lines received), MailBee will still add this attachment into Attachments collection, but the attachment binary data will obviously be incomplete.
Note 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.
| Exception Type | Condition |
|---|---|
| MailBeeException | An error occurred and ThrowExceptions is true. |
This sample downloads the header and 300 lines (approx. 20-30 KBytes) of the message source body for every message in an inbox on a POP3 server, and displays whether the messages probably contain attachments or not.
Note If no attachment is found in a partial message, there is still no guarantee the message would not contain attachments if was downloaded completely; the message may just have a large body text section which spans more than 300 lines in the entire message. If more body lines (such as 1000) are downloaded with the header, attachment detection quality will be higher, but at the cost of increased network traffic with the server. Another approach is to use HasAttachments property, however, it's still not 100% accurate, because it may indicate the message does have attachments if it actually doesn't but the message header reports the message has at least one attachment.
[C#] // 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.Connect("mail.domain.com"); pop.Login("jdoe", "secret"); MailMessageCollection msgs = pop.DownloadMessageHeaders(1, -1, 300); foreach (MailMessage msg in msgs) { string attachmentStatus = msg.Attachments.Count == 0 ? "no" : "some"; Console.WriteLine("Message #" + msg.IndexOnServer + " probably contains " + attachmentStatus + " attachment(s)"); } pop.Disconnect();
[Visual Basic] ' To use the code below, import MailBee namespaces at the top of your code. Imports MailBee Imports MailBee.Pop3Mail Imports MailBee.Mime ' The actual code (put it into a method of your class). Dim pop As New Pop3 pop.Connect("mail.domain.com") pop.Login("jdoe", "secret") Dim msgs As MailMessageCollection msgs = pop.DownloadMessageHeaders(1, -1, 300) For Each msg As MailMessage In msgs Dim attachmentStatus As String If msg.Attachments.Count = 0 Then attachmentStatus = "no" Else attachmentStatus = "some" End If Console.WriteLine("Message #" & msg.IndexOnServer & " probably contains " & _ attachmentStatus & " attachment(s)") Next pop.Disconnect()
Pop3 Class | MailBee.Pop3Mail Namespace | Pop3.DownloadMessageHeaders Overload List