ImapErrorOccurred Event
Occurs when the MailBeeException is thrown.

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


Type: MailBeeErrorEventHandler

When MailBee encounters any error, it throws the MailBeeException. However, MailBee can trap this exception if the error was not critical. For instance, if the IMAP4 server responds with a FETCH response containing envelope data which could not be completely parsed, the MailBeeException will be thrown and then trapped by MailBee itself, but no exception will be thrown to the application code. Such errors are called warnings.

ErrorOccurred event allows the developer to track both warnings and critical errors because it's raised for a particular exception even if MailBee will trap this exception and do not pass it to the application code.

This sample logs all the warnings and critical errors issued during the IMAP4 session into the console. If the connection succeeds and all envelopes are received without any errors, no output will be produced. The sample is written for a console application.
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
    // ErrorOccurred event handler.
    private static void OnErrorOccurred(object sender, ErrorEventArgs e)
        // Check whether the error is critical or not.
        if (e.IsFinalError)
            // Display corresponding MailBeeException.Message.
            // After OnErrorOccurred handler finishes, MailBee will 
            // throw the same exception to the application code.
            Console.WriteLine("CRITICAL ERROR: " + e.Reason.Message);
            // Display corresponding MailBeeException.Message.
            // After OnErrorOccurred handler finishes, MailBee will 
            // try another methods to accomplish the current task.
            Console.WriteLine("WARNING: " + e.Reason.Message);

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

        // Subscribe to the ErrorOccurred event.
        imp.ErrorOccurred += new ErrorEventHandler(OnErrorOccurred);

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

        // Download envelopes. If any envelopes could not be completely parsed,
        // this will caused ErrorOccurred event be raised.
        EnvelopeCollection envs = imp.DownloadEnvelopes(Imap.AllMessages, false);

        // Close the connection
See Also