Pop3SocketConnected Event |
Namespace: MailBee.Pop3Mail
Once Connect(String, Int32, Boolean) method finishes, all event handlers are removed in the code, thus Disconnect method does not generate any events (but it would do if we didn't remove LowLevelDataReceived and DataReceived handlers).
DataSent and LowLevelDataSent events are not used in this sample because Connect(String, Int32, Boolean) method does not send any data to the server. However, it would be different if SSL-encrypted connection was used.
using System; using MailBee; using MailBee.Pop3Mail; class Sample { // HostResolved event handler. private static void OnHostResolved(object sender, HostResolvedEventArgs e) { Console.WriteLine("The host name of the server was resolved into IP address."); } // SocketConnected event handler. private static void OnSocketConnected(object sender, SocketConnectedEventArgs e) { Console.WriteLine("The server accepted the connection."); } // LowLevelDataReceived event handler. private static void OnLowLevelDataReceived(object sender, DataTransferEventArgs e) { // Since SSL connection is not used, OnDataReceived and OnLowLevelDataReceived // routines will produce the same output. This sample handles both events just // to demonstrate that LowLevelDataReceived event is raised before the // corresponding DataReceived event. // But in SSL case, DataReceived and LowLevelDataReceived event data would be // completely different, and some LowLevelDataReceived events (such as ones // occurred during the SSL handshake) would not be followed by DataReceived // events at all, because the data sent or received during the SSL handshake // does not relate to POP3 protocol and cannot be decoded into textual form. Console.WriteLine("Low level data received: [" + System.Text.Encoding.Default.GetString(e.Data) + "]"); } // DataReceived event handler. private static void OnDataReceived(object sender, DataTransferEventArgs e) { Console.WriteLine("Data received: [" + System.Text.Encoding.Default.GetString(e.Data) + "]"); } // Connected event handler. private static void OnConnected(object sender, ConnectedEventArgs e) { Console.WriteLine("Successfully connected to the server."); } // The actual code. static void Main(string[] args) { Pop3 pop = new Pop3(); // Subscribe to the events. pop.HostResolved += new HostResolvedEventHandler(OnHostResolved); pop.SocketConnected += new SocketConnectedEventHandler(OnSocketConnected); pop.LowLevelDataReceived += new DataTransferEventHandler(OnLowLevelDataReceived); pop.DataReceived += new DataTransferEventHandler(OnDataReceived); pop.Connected += new ConnectedEventHandler(OnConnected); // Connect to the server and make the events get raised. pop.Connect("mail.domain.com"); // Unsubscribe from the events. pop.HostResolved -= new HostResolvedEventHandler(OnHostResolved); pop.SocketConnected -= new SocketConnectedEventHandler(OnSocketConnected); pop.LowLevelDataReceived -= new DataTransferEventHandler(OnLowLevelDataReceived); pop.DataReceived -= new DataTransferEventHandler(OnDataReceived); pop.Connected -= new ConnectedEventHandler(OnConnected); pop.Disconnect(); } }