SmtpDataReceived Event |
Namespace: MailBee.SmtpMail
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. |
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"); } }