MailBee.NET Objects 3.1

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

Completely downloads the specified message from the specified folder on the server, in a single line of code.

public static MailMessage QuickDownloadMessage(
   string serverName,
   string accountName,
   string password,
   string folderName,
   int messageNumber
);

Parameters

serverName
The name or IP address of the IMAP4 server.
accountName
The user account name on the server.
password
The password of the user account on the server.
folderName
The full name of the folder to download the message from.
messageNumber
The ordinal position of the message in the folder, starting at 1.

Return Value

A MailMessage object containing the downloaded message (including the header and all the body parts and attachments).

Remarks

This method does not delete any messages in the folder.

An account on the mail server is guaranteed to contain at least "Inbox" folder. The "Inbox" name is case-sensitive ("Inbox", "inbox", and "INBOX" are equivalent). Other folder names, however, may be case-senstive depending on the server implementation.

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

Note   Static methods still require the valid license key 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 downloads the first message in the inbox and saves it as .EML file to disk.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

// The actual code (put it into a method of your class).
MailMessage msg = Imap.QuickDownloadMessage("imap.domain.com",
    "login@domain.com", "password", "Inbox", 1);
msg.SaveMessage(@"C:\Temp\message.eml");
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.ImapMail
Imports MailBee.Mime

' The actual code (put it into a method of your class).
Dim msg As MailMessage = Imap.QuickDownloadMessage("imap.domain.com", _
    "login@domain.com", "password", "Inbox", 1)
msg.SaveMessage("C:\Temp\message.eml")

See Also

Imap Class | MailBee.ImapMail Namespace | Imap.QuickDownloadMessage Overload List | QuickDownloadMessages