ImapDisconnected Event
Occurs when the connection with the server gets closed.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
public event DisconnectedEventHandler Disconnected


Type: MailBeeDisconnectedEventHandler
This event is raised in all the cases when the connection gets closed, including normal shutdown and failures.
Note Note
If Abort method is called, the connection is immediately closed, but no events (including Disconnected) are raised any longer.
This sample demonstrates that Disconnected event raises even on failures (when MailBeeException is thrown). The sample set very small timeout value (500 milliseconds), then attempts to connect to the IMAP4 server, log in the account, select Inbox folder, and download the first message. If the server or network connection is slow, the network operation will time out. Otherwise, it will succeed. But in both cases, Disconnected will still be raised.
using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

class Sample
    // Disconnected event handler.
    private static void OnDisconnected(object sender, DisconnectedEventArgs e)
        if (e.IsNormalShutdown)
            // LOGOUT command was sent to IMAP4 server.
            Console.WriteLine("Normally disconnected from the server.");
            // Rough disconnect (due to failure). This will occur if the server
            // or network connection is quite slow and typical delay exceeds
            // 500 milliseconds timeout value which we set for this sample.
            Console.WriteLine("The connection was terminated.");

    // The actual code.
    static void Main(string[] args)
        Imap imp = new Imap();

        // Set relatively small timeout value. Under slow connection,
        // it may cause the connection to be closed due to timeout.
        imp.Timeout = 500;

        // Subscribe to Disconnected event.
        imp.Disconnected += new DisconnectedEventHandler(OnDisconnected);

        // Connect to the server, login and select inbox.
        imp.Login("", "secret");

        // Download the first message in the inbox completely. If the connection is
        // slow, this may cause MailBee to terminate the connection and raise 
        // Disconnected event, and then throw MailBeeException (exceptions are 
        // enabled by default).
        MailMessage msg = imp.DownloadEntireMessage(1, false);

        // Close the connection normally.
See Also