MailBee.NET Objects 4.0

Pop3.QuickDownloadMessage Method (String, String, String, Int32, Int32)

Downloads the specified message (entire message or message header only) from the server, in a single line of code.

public static MailMessage QuickDownloadMessage(
   string serverName,
   string accountName,
   string password,
   int index,
   int bodyLineCount
);

Parameters

serverName
The name or IP address of the POP3 server.
accountName
The user account name on the server.
password
The password of the user account on the server.
index
The ordinal position of the message in the inbox, starting at 1.
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, or 0 to download the message header only.

Return Value

A MailMessage object containing the downloaded message.

Remarks

This method does not delete any messages in the inbox.

The common use of this method is to quickly receive the message or its part when its index in the inbox is already known. For instance, QuickDownloadMessages method was used to download headers for all messages in the inbox and build the message list where the user can click a particular message to view it in more detail. Once the user selected the message to be viewed, the application passes its index in the message list as a value of index parameter of QuickDownloadMessage method to download the selected message or its part (if the message list index is zero-based, the developer should also add 1 to the index value).

Note   Static methods still require the valid license key to be assigned to LicenseKey property (by either setting in in the code or in the config file such as app.config). All samples in MailBee documentation assume the license key is already set in the config file.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred.

Example

This sample partially downloads the first message in the inbox (the header and the first 100 lines of the message source body are downloaded), and displays preview of the plain-text body of the message. This may be useful if the entire message is very large, and the user wants to take a look at the beginning of the body text in order to decide whether to download the entire message.

If the message has HTML part but does not have plain-text part, the plain-text version will be generated automatically.

[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).
MailMessage msg = Pop3.QuickDownloadMessage("pop.server.com",
    "login", "password", 1, 100);
msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain;
Console.WriteLine(msg.BodyPlainText);
[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 msg As MailMessage = Pop3.QuickDownloadMessage("pop.server.com", _
    "login", "password", 1, 100)
msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain
Console.WriteLine(msg.BodyPlainText)

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | Pop3.QuickDownloadMessage Overload List | QuickDownloadMessages