Pop3ErrorOccurred Event |
Namespace: MailBee.Pop3Mail
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 POP3 server responds with a negative reply to an optional POP3 command (such as CAPA), 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.
using System; using MailBee; using MailBee.Pop3Mail; 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) { Pop3 pop = new Pop3(); // Subscribe to the ErrorOccurred event. pop.ErrorOccurred += new ErrorEventHandler(OnErrorOccurred); // Connect to the server. pop.Connect("mail.domain.com"); // Request any data which needs CAPA command to be issued // in order to obtain the required information. The list of supported // authentication methods can serve this purpose. If CAPA command // fails (but the server responds, i.e. the connection itself is still valid), // MailBee will not throw any exception to the application code // (but ErrorOccurred event will still be raised) and will try to issue // AUTH command to get the list of supported authentication methods. // If AUTH command fails too, it's still not a critical error. SASL // authentication methods will just not be available. AuthenticationMethods authMethods = pop.GetSupportedAuthMethods(); // Close the connection pop.Disconnect(); } }