Capturing Pop related events |
The Pop class may publish one or more events during the lifetime of an Pop session. Any object that subscribes to events published by the Pop class can receive and process these events.
The ConnectedEvent is fired by the Pop instance once a connection to the POP server has been established. The DisconnectedEvent is fired by the Pop instance once the connection to the POP server has been released. The CommandSentEvent is fired by the Pop instance for each command sent to the POP server. The DataReceivedEvent is fired by the Pop instance for each response received from the POP server. The MessageRetrievedEvent is fired by the Pop instance for each message retrieved from the POP server.
Capturing the ConnectedEvent event
The ConnectedEvent is published by the Pop instance once a connection to the POP server has been established.
Example
[C#] myPop = new Pop(hostname, username, password); // Subscribe to event myPop.ConnectedEvent += new Pop.ConnectedEventHandler(OnConnected);
// Define Connected Event handler public void OnConnected(object sender, PopConnectedEventArgs e) { Console.WriteLine("Connected to {0}", e.Host); }
[Visual Basic] Public WithEvents myPop As Pop myPop = New Smtp(hostname, username, password);
' Define Connected Event handler Private Sub OnConnected( ByVal sender As Object, ByVal e As PopConnectedEventArgs) Handles myPop.ConnectedEvent Console.WriteLine("Connected to {0}", e.Host); End Sub
Capturing the DisconnectedEvent event
The DisconnectedEvent is published by the Pop instance once the connection to the POP server has been released.
Example
[C#] myPop = new Pop(hostname, username, password); // Subscribe to event myPop.DisconnectedEvent += new Pop.DisconnectedEventHandler(OnDisconnected);
// Define Disconnected Event handler public void OnDisconnected(object sender, PopDisconnectedEventArgs e) { Console.WriteLine("Disconnected"); }
[Visual Basic] Public WithEvents myPop As Pop myPop = New Pop(hostname, username, password);
' Define Disconnected Event handler Private Sub OnDisconnected( ByVal sender As Object, ByVal e As PopDisconnectedEventArgs) Handles myPop.DisconnectedEvent Console.WriteLine("Disconnected"); End Sub
Capturing the CommandSentEvent event
The CommandSentEvent is published by the Pop instance for each command sent to the POP server.
Example
[C#] myPop = new Pop(hostname, username, password); // Subscribe to event myPop.CommandSentEvent += new Pop.CommandSentEventHandler(OnCommandSent);
// Define CommandSent Event handler public void OnCommandSent(object sender, PopCommandSentEventArgs e) { Console.WriteLine("Command: " + e.Command); }
[Visual Basic] Public WithEvents myPop As Pop myPop = New Pop(hostname, username, password);
' Define CommandSent Event handler Private Sub OnCommandSent( ByVal sender As Object, ByVal e As PopCommandSentEventArgs) Handles myPop.CommandSentEvent Console.WriteLine("Command: " & e.Command); End Sub
Capturing the DataReceivedEvent event
The DataReceivedEvent is published by the Pop instance for each response received from the POP server.
Example
[C#] myPop = new Pop(hostname, username, password); // Subscribe to event myPop.DataReceivedEvent += new Pop.DataReceivedEventHandler(OnDataReceived);
// Define DataReceived Event handler public void OnDataReceived(object sender, PopDataReceivedEventArgs e) { Console.WriteLine("Response: " + e.Response); }
[Visual Basic] Public WithEvents myPop As Pop myPop = New Pop(hostname, username, password);
' Define DataReceived Event handler Private Sub OnDataReceived( ByVal sender As Object, ByVal e As PopDataReceivedEventArgs) Handles myPop.DataReceivedEvent Console.WriteLine("Response: " & e.Response); End Sub
Capturing the MessageRetrievedEvent event
The MessageRetrievedEvent is published by the Pop instance for each message retrieved from the POP server.
Example
[C#] myPop = new Pop(hostname, username, password); // Subscribe to event myPop.MessageRetrievedEvent += new Pop.MessageRetrievedEventHandler(OnMessageRetrieved);
// Define MessageRetrieved Event handler public void OnMessageRetrieved(object sender, PopMessageRetrievedEventArgs e) { Console.WriteLine("Message: " + e.Message.GetSubject()); }
[Visual Basic] Public WithEvents myPop As Pop myPop = New Pop(hostname, username, password);
' Define MessageRetrieved Event handler Private Sub OnMessageRetrieved( ByVal sender As Object, ByVal e As PopMessageRetrievedEventArgs) Handles myPop.MessageRetrievedEvent Console.WriteLine("Message: " & e.Message.GetSubject()); End Sub
|