Occurs when data is received from 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 when any encrypted chunk of data is received. Thus, this event can be used to record the data which is actually received from the network.
The typical use of this property is to calculate the network traffic produced during the SMTP session (including POP3/DNS data if any). 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 DataReceived.
This sample calculates all incoming traffic from 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 received counters. private static int _totalBytesSmtp = 0; private static int _totalBytesDns = 0; // LowLevelDataReceived event handler. private static void OnLowLevelDataReceived(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 LowLevelDataReceived event. mailer.LowLevelDataReceived += new DataTransferEventHandler(OnLowLevelDataReceived); // 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 received from the network. Console.WriteLine(_totalBytesSmtp + " bytes received in all SMTP sessions"); Console.WriteLine(_totalBytesDns + " bytes received in all DNS responses"); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Class Sample ' Total bytes received counters. Private Shared _totalBytesSmtp = 0 Private Shared _totalBytesDns = 0 ' LowLevelDataReceived event handler. Private Shared Sub OnLowLevelDataReceived(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 LowLevelDataReceived event. AddHandler mailer.LowLevelDataReceived, AddressOf OnLowLevelDataReceived ' 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 received from the network. Console.WriteLine(_totalBytesSmtp + " bytes received in all SMTP sessions") Console.WriteLine(_totalBytesDns + " bytes received in all DNS responses") End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace | DataReceived