MailBee.NET Objects 4.0

Imap.ServerStatus Event

Occurs when the IMAP4 server reports mailbox or server status information to the client.

public event ImapServerStatusEventHandler ServerStatus;

Event Data

The event handler receives an argument of type ImapServerStatusEventArgs containing data related to this event. The following ImapServerStatusEventArgs properties provide information specific to this event.

Property Description
Details Gets the response body.
HumanReadable Gets the human readable part of the status response.
IsAlert Gets whether the status response is "[ALERT]" response.
OptionalData Gets the contents of the optional response code of the response.
State Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components.
StatusID Gets the status string of the current response.

Remarks

The server sends the status response to the client when a command is completed or there is a state change of the server or the currently folder, etc.

MailBee raises this event when it receives any of the following responses from the server: OK, NO, BAD, PREAUTH, BYE, or FLAGS.

The real-world application should subscribe to this event and at least check IsAlert property value. If it's true, it means the server sent [ALERT] response along with the human-readable message, and the application must present the supplied HumanReadable text to the user. For instance, the server may tell clients it's about to shutdown in a short while.

Example

This sample connects to the server, logs in the account, selects inbox, and receives envelopes of all messages. If the server sends [ALERT] response during this time, it's displayed to the user.

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

class Sample
{
    // ServerStatus event handler.
    private static void OnServerStatus(object sender,
        ImapServerStatusEventArgs e)
    {
        if (e.IsAlert)
        {
            Console.WriteLine("The server warns: " + e.HumanReadable);
        }
    }

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

        // Subscribe to ServerStatus event.
        imp.ServerStatus +=
            new ImapServerStatusEventHandler(OnServerStatus);

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

        // Download envelopes of all message in the inbox.
        EnvelopeCollection envs = imp.DownloadEnvelopes(Imap.AllMessages, false);

        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    ' ServerStatus event handler.
    Private Sub OnServerStatus(ByVal sender As Object, ByVal e As ImapServerStatusEventArgs)
        If e.IsAlert Then
            Console.WriteLine("The server warns: " & e.HumanReadable)
        End If
    End Sub

    ' The actual code.
    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Subscribe to ServerStatus event.
        AddHandler imp.ServerStatus, AddressOf OnServerStatus

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

        ' Download envelopes of all message in the inbox.
        Dim envs As EnvelopeCollection = imp.DownloadEnvelopes(Imap.AllMessages, False)

        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | MessageStatus