PowerTCP Mail for .NET
Trace Event
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Smtp Class : Trace Event




Raised when data has been sent/received.

Syntax

Visual Basic (Declaration) 
<CategoryAttribute("Progress")>
<DescriptionAttribute("Raised when data has been sent/received over the control connection.")>
Public Event Trace As SegmentEventHandler
Visual Basic (Usage)Copy Code
Dim instance As Smtp
Dim handler As SegmentEventHandler
 
AddHandler instance.Trace, handler
C# 
[CategoryAttribute("Progress")]
[DescriptionAttribute("Raised when data has been sent/received over the control connection.")]
public event SegmentEventHandler Trace
Managed Extensions for C++ 
[CategoryAttribute("Progress")]
[DescriptionAttribute("Raised when data has been sent/received over the control connection.")]
public: __event SegmentEventHandler* Trace
C++/CLI 
[CategoryAttribute("Progress")]
[DescriptionAttribute("Raised when data has been sent/received over the control connection.")]
public:
event SegmentEventHandler^ Trace

Event Data

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

PropertyDescription
Exception Gets any exception which occurred during the asynchronous operation.
Segment The Segment object referencing the data that was sent or received.
State Gets the object that was included as part of the associated method call.

Example

The following example demonstrates using the Trace event to create a log of TCP communication.
Visual BasicCopy Code
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail"
' at the top of your class.

Private Sub TraceTest()
   ' Do something to cause the Trace event to be raised
   Smtp1.Server = "mail.test.com"
   Smtp1.Send("you@test.com", "me@test.com", "test", "test message")
End Sub

Private Sub Smtp1_Trace(ByVal sender As Object, ByVal e As Dart.PowerTCP.Mail.SegmentEventArgs) Handles Smtp1.Trace
   ' Get the 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:\test\smtptracevb.log", FileMode.Append)

   ' Write the data to the file.
   f.Write(buffer, 0, buffer.Length)
   f.Close()
End Sub
C#Copy Code
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;"
// at the top of your class.

private void TraceTest()
{
   // Do something to cause the Trace event to be raised
   smtp1.Server = "mail.test.com";
   smtp1.Send("you@test.com", "me@test.com", "test", "test message");
}

private void smtp1_Trace(object sender, Dart.PowerTCP.Mail.SegmentEventArgs e)
{
   // Get the data into a byte array
   byte[] buffer = System.Text.Encoding.Default.GetBytes(e.Segment.ToString());
			
   // Create a FileStream
   FileStream f = new FileStream("C:\\test\\smtptracecsharp.log", FileMode.Append);

   // Write the data to the file.
   f.Write(buffer, 0, buffer.Length);
   f.Close();
}

Remarks

This event is raised when commands or data has been sent/received. If you are using a component which uses TCP as the transport protocol a SegmentEventArgs object is passed into the event containing any commands or data sent or received. If you are using a component which uses UDP as the transport protocol a DatagramEventArgs object is passed into the event containing any commands or data sent or received.

The Object.RawTrace event always reports actual data sent/received over the socket. The Count of each segment reflects the number of bytes actually written and received. The Object.Trace event reports data sent/received at a higher level. For example, for the Telnet component, Object.Trace reports data sent/received, but does not report IAC option sequences that are processed by TelnetStream, whereas Object.RawTrace allows you to trace the actual data sent/received, including Telnet option commands.

If you are using the PowerTCP component as a reference, you must create a method to handle the event yourself. For more information on using events using PowerTCP.NET within the Visual Studio.NET environment, see Using Events In PowerTCP.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.