Occurs when data is sent to the connected socket.
The event handler receives an argument of type DataTransferEventArgs containing data related to this event. The following DataTransferEventArgs properties provide information specific to this event.
| Property | Description |
|---|---|
| Data | Gets a reference to the data block (chunk) sent or received. |
| Protocol | Gets application-level protocol of the current connection. |
| RemoteEndPoint | Gets a reference to the end point of the server host. |
| RemoteHostName | Gets the host name of the server. |
| State | Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components. |
If the transmission channel is encrypted, this event will be raised each time an encrypted chunk of data is successfully sent. Thus, this event can be used to record the data which is actually sent to the network.
The typical use of this event is to calculate the network traffic produced during the SMTP session. SSL encryption increases the length of the transmitted data blocks, thus it's more accurate to calculate traffic by counting the length of data actually transmitted over the network.
If the transmission channel is not encrypted or otherwise scrambled, this property is equivalent to DataSent.
This sample calculates all outgoing traffic to the network during sending the message in direct send mode. DNS MX lookup traffic and SMTP traffic are calculated separately, and the results are printed into console.
[C#] using System; using MailBee; using MailBee.SmtpMail; class Sample { // Total bytes sent counters. private static int _totalBytesSmtp = 0; private static int _totalBytesDns = 0; // LowLevelDataSent event handler. private static void OnLowLevelDataSent(object sender, DataTransferEventArgs e) { if (e.Protocol == TopLevelProtocolType.Smtp) { // Increment SMTP traffic counter. _totalBytesSmtp += e.Data.Length; } else if (e.Protocol == TopLevelProtocolType.Dns) { // Increment DNS traffic counter. _totalBytesDns += e.Data.Length; } } // The actual code. static void Main(string[] args) { Smtp mailer = new Smtp(); // Get DNS servers from config file/OS settings. mailer.DnsServers.Autodetect(); // Subscribe to the LowLevelDataSent event. mailer.LowLevelDataSent += new DataTransferEventHandler(OnLowLevelDataSent); // Produce some DNS and SMTP traffic by performing direct send of empty message. mailer.Send("sender@domain.com", "user1@domain1.com, user2@domain2.com"); // Print the total number of bytes sent to the network. Console.WriteLine(_totalBytesSmtp + " bytes sent in all SMTP sessions"); Console.WriteLine(_totalBytesDns + " bytes sent in all DNS queries"); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Class Sample ' Total bytes sent counters. Private Shared _totalBytesSmtp = 0 Private Shared _totalBytesDns = 0 ' LowLevelDataReceived event handler. Private Shared Sub OnLowLevelDataSent(ByVal sender As Object, ByVal e As DataTransferEventArgs) If e.Protocol = TopLevelProtocolType.Smtp Then ' Increment SMTP traffic counter. _totalBytesSmtp += e.Data.Length ElseIf e.Protocol = TopLevelProtocolType.Dns Then ' Increment DNS traffic counter. _totalBytesDns += e.Data.Length End If End Sub ' The actual code. Shared Sub Main(ByVal args As String()) Dim mailer As New Smtp ' Get DNS servers from config file/OS settings. mailer.DnsServers.Autodetect() ' Subscribe to the LowLevelDataSent event. AddHandler mailer.LowLevelDataSent, AddressOf OnLowLevelDataSent ' Produce some DNS and SMTP traffic by performing direct send of empty message. mailer.Send("sender@domain.com", "user1@domain1.com, user2@domain2.com") ' Print the total number of bytes sent to the network. Console.WriteLine(_totalBytesSmtp & " bytes sent in all SMTP sessions") Console.WriteLine(_totalBytesDns & " bytes sent in all DNS queries") End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace | DataSent