MailBee.NET Objects 4.0

Imap.DownloadEntireMessage Method 

Completely downloads the specified message from the server.

public MailMessage DownloadEntireMessage(
   long messageIndex,
   bool indexIsUid
);

Parameters

messageIndex
The ordinal position or UID of the message in the currently selected folder.
indexIsUid
If true, messageIndex is treated as UID; otherwise, as ordinal message number.

Return Value

On success, a MailMessage object containing the entire message, including the message header, all the body parts and attachments; otherwise, a null reference (Nothing in Visual Basic).

Remarks

If more than one message is downloaded, it's recommended to use DownloadEntireMessages method when possible, since it is capable of downloading multiple messages in a batch.

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

This sample downloads the first message from an inbox on an IMAP4 server, saves it as index.htm file, and also saves the embedded pictures and other linked objects, making it possible to open index.htm file in a browser and have the message being correctly displayed (including all the graphics, styles, etc).

[C#]
using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Connect("imap.somehost.com");
        imp.Login("jdoe@somehost.com", "secret");
        imp.SelectFolder("INBOX");

        // Save message as C:\Temp\index.htm
        MailMessage msg = imp.DownloadEntireMessage(1, false);
        msg.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml;
        msg.SaveHtmlAndRelatedFiles(@"C:\Temp\index.htm");

        // Disconnect from the server.
        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail
Imports MailBee.Mime

Module Sample
    Sub Main()
        Dim imp As New Imap

        ' Connect to the server, login and select inbox.
        imp.Connect("imap.somehost.com")
        imp.Login("jdoe@somehost.com", "secret")
        imp.SelectFolder("INBOX")

        ' Save message as C:\Temp\index.htm
        Dim msg As MailMessage = imp.DownloadEntireMessage(1, False)
        msg.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml
        msg.SaveHtmlAndRelatedFiles("C:\Temp\index.htm")

        ' Disconnect from the server.
        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | DownloadEntireMessages | DownloadEnvelopes