Anytime data is sent or received over the TCP connection, the Trace event is raised. Made accessible to this event is the data sent. The Trace event makes it easy to create a text log of data sent/received.
To create a log of commands, use the following steps:
- Add the Pop component to a new form.
- Import the namespace of the component you would like to use using "Using" (C#) or "Imports" (VB.NET). Place the following code at the top of your file. Also, import System.IO as a FileStream will be used in this example.
C#
Copy Codeusing Dart.PowerTCP.Mail; using System.IO;
Visual Basic
Copy CodeImports Dart.PowerTCP.Mail Imports System.IO
- The Pop.Trace event will be raised when data is sent or received. "Wire-up" the Pop.Trace event. Set the properties required to properly get all messages from the server.
-
Place the following code in the Click event of the button added to the form in step 3.
C#
Copy Code// Be sure the Pop component is configured to automatically retrieve messages. pop1.AutoGet = MessageSection.Complete;Visual Basic
Copy Code' Be sure the Pop component is configured to automatically retrieve messages. Pop1.AutoGet = Complete - Login to the server. All messages will be automatically retrieved. Since Pop.AutoLogout is set to it's default value (true), logout will automatically occur once login has completed. Place this code directly after the code from step 5.
C#
Copy Code// Login to the POP server. pop1.Login("mail.myserver.com", "test", "pass");
Visual Basic
Copy Code' Login to the POP server. Pop1.Login("mail.myserver.com", "test", "pass")
- Add code to the Pop.Trace event to display the data sent/received.
C#
Copy Codeprivate void pop1_Trace(object sender, Dart.PowerTCP.Mail.SegmentEventArgs e) { // Get the event data into a byte array. byte[] buffer = System.Text.Encoding.Default.GetBytes(e.Segment.ToString()); // Create a FileStream FileStream f = new FileStream("C:\\temp\\poplog.log", FileMode.Append); // Write the data to the stream f.Write(buffer, 0, buffer.Length); // Close the FileStream f.Close(); }
Visual Basic
Copy CodePrivate Sub Pop1_Trace(ByVal sender As Object, ByVal e As Dart.PowerTCP.Mail.SegmentEventArgs) Handles Pop1.Trace ' Get the event data into a byte array. Dim buffer As Byte() = System.Text.Encoding.Default.GetBytes(e.Segment.ToString()) ' Create a FileStream Dim f As New FileStream("C:\temp\poplog.log", FileMode.Append) ' Write the data to the stream f.Write(buffer, 0, buffer.Length) ' Close the FileStream f.Close() End Sub
- Compile and run the application. After it successfully runs, check the log file. You should be able to see the communication required to get all of the messages.