Occurs when data is received from the network.
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. |
Usually, this event is raised when the component receives a response from an SMTP server. If direct send mode is used, DNS responses containing MX lookup results will also be returned. If POP-before-SMTP authentication is used, POP3 responses will be returned as well. The developer can use Protocol property to determine the protocol of the received response data.
Unlike LowLevelDataReceived event, occurrence of this event indicates receiving of already decrypted data. For instance, if the transmission channel is SSL-encrypted, LowLevelDataReceived event indicates receiving of encrypted data, while DataReceived will be raised later (after decrypting the data). If the transmission channel is not encrypted or otherwise scrambled, DataReceived and LowLevelDataReceived are equivalent.
Note This event is also raised when zero-length data is received from the server. When a server sends zero-length data portion, it means the connection was closed.
This sample prints all the data received from the server during SMTP session into console.
[C#] using System; using MailBee; using MailBee.SmtpMail; class Sample { // DataReceived event handler. private static void OnDataReceived(object sender, DataTransferEventArgs e) { // Ignore DNS traffic. if (e.Protocol == TopLevelProtocolType.Smtp) { Console.WriteLine("[" + System.Text.Encoding.Default.GetString(e.Data) + "]"); } } // 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 DataReceived event. mailer.DataReceived += new DataTransferEventHandler(OnDataReceived); // Produce some DNS and SMTP traffic by performing direct send of empty message. mailer.Send("sender@domain.com", "recipient@domain.com"); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Class Sample ' DataReceived event handler. Private Shared Sub OnDataReceived(ByVal sender As Object, ByVal e As DataTransferEventArgs) ' Ignore DNS traffic. If e.Protocol = TopLevelProtocolType.Smtp Then Console.WriteLine("[" & System.Text.Encoding.Default.GetString(e.Data) & "]") 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 DataReceived event. AddHandler mailer.DataReceived, AddressOf OnDataReceived ' Produce some DNS and SMTP traffic by performing direct send of empty message. mailer.Send("sender@domain.com", "recipient@domain.com") End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace | LowLevelDataReceived