MailBee.NET Objects 4.0

Pop3.DownloadMessageHeader Method (Int32, Int32)

Downloads the header and the specified number of body lines of the message on the server.

public MailMessage DownloadMessageHeader(
   int index,
   int bodyLineCount
);

Parameters

index
The ordinal position of the message in the inbox. It must be in the range 1 to InboxMessageCount.
bodyLineCount
Number of lines of the message source body to download in addition to the message source header, or -1 to download the entire message.

Return Value

On success, a MailMessage object containing the downloaded partial message; otherwise, a null reference (Nothing in Visual Basic).

Remarks

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 more than one message header is downloaded, it's recommended to use DownloadMessageHeaders method when possible, since it can operate much faster if the server supports pipelining.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample downloads the header and 20 lines of the message source body for the last message in an inbox on a POP3 server, and prints the message body text (if any) MailBee managed to extract from the downloaded 20 lines of the message source body.

[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");
MailMessage msg = pop.DownloadMessageHeader(pop.InboxMessageCount, 20);
Console.WriteLine(msg.BodyPlainText);
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 msg As MailMessage
msg = pop.DownloadMessageHeader(pop.InboxMessageCount, 20)
Console.WriteLine(msg.BodyPlainText)
pop.Disconnect()

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | Pop3.DownloadMessageHeader Overload List | DownloadMessageHeaders