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 Smtp 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 Trace event will be raised when data is sent or received. "Wire-up" the Trace event. Add a button to the form.
- Send a quick message. Place the following code in the Click event of the button added to the form in step 3.
C#
Copy Code// Set the server smtp1.Server = "mail.test.com"; // Send a message smtp1.Send("test@yourserver.com", "me@myserver.com", "test", "This is a test.");
Visual Basic
Copy Code' Set the server Smtp1.Server = "mail.test.com" ' Send a message Smtp1.Send("test@yourserver.com", "me@myserver.com", "test", "This is a test.")
- Add code to the Trace event to display the data sent/received.
C#
Copy Codeprivate void smtp1_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\\smtplog.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 Smtp1_Trace(ByVal sender As Object, ByVal e As Dart.PowerTCP.Mail.SegmentEventArgs) Handles Smtp1.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\smtplog.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.