ImapErrorOccurred Event
Occurs when the MailBeeException is thrown.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public event ErrorEventHandler ErrorOccurred

Value

Type: MailBeeErrorEventHandler
Remarks

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.

Examples
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);
        }
        else
        {
            // 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.Connect("mail.company.com");
        imp.Login("jdoe@company.com", "secret");
        imp.SelectFolder("INBOX");

        // 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
        imp.Disconnect();
    }
}
See Also