Occurs on progress of sending message source data to the SMTP server.
The event handler receives an argument of type SmtpMessageDataChunkSentEventArgs containing data related to this event. The following SmtpMessageDataChunkSentEventArgs properties provide information specific to this event.
| Property | Description |
|---|---|
| BytesJustSent | Gets the number of bytes sent to the server during the operation which raised the current event. |
| DataTotalLength | Gets the length (in bytes) of the message data being sent. |
| MailMessage | Gets the mail message which is being sent. |
| State | Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components. |
| TotalBytesSent | Gets the total length (in bytes) of the already sent data of the message currently being sent. |
This event is a special case of DataSent event. While DataSent event occurs when any data is sent, MessageDataChunkSent event indicates when message data is being sent. In other words, MessageDataChunkSent event is a filtered version of more general DataSent event.
When both DataSent and MessageDataChunkSent events are used, DataSent is raised first.
This sample submits a mail message to the SMTP server. Both DataSent and MessageDataChunkSent events are handled, and the corresponding messages are printed into console when each of these events is raised. This sample demonstrates that DataSent is raised more often than MessageDataChunkSent.
[C#] using System; using MailBee; using MailBee.SmtpMail; class Sample { // DataSent event handler. private static void OnDataSent(object sender, DataTransferEventArgs e) { Console.WriteLine(e.Data.Length + " bytes sent"); } // MessageDataChunkSent event handler. private static void OnMessageDataChunkSent(object sender, SmtpMessageDataChunkSentEventArgs e) { Console.WriteLine(e.BytesJustSent + " bytes of the message " + e.MailMessage.MessageID + " sent"); } // The actual code. static void Main(string[] args) { Smtp mailer = new Smtp(); // Specify SMTP server and enable ESMTP authentication. // Note, depending on your SMTP server settings, either // "jdoe" or "jdoe@domain.com" should be used as user account name. mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret"); // Subscribe to events. mailer.DataSent += new DataTransferEventHandler(OnDataSent); mailer.MessageDataChunkSent += new SmtpMessageDataChunkSentEventHandler(OnMessageDataChunkSent); // Send a message (attach a big file to make the message be sent // in multiple data chunks). mailer.To.AsString = "recipient1@domain1.com, recipient2@domain2.com"; mailer.From.Email = "sender@domain.com"; mailer.Subject = "Test message"; mailer.BodyPlainText = "The message with attachment"; mailer.AddAttachment(@"C:\bigfile.mdb"); mailer.Send(); Console.WriteLine("Message sent to: " + mailer.GetAcceptedRecipients().ToString()); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Class Sample ' DataSent event handler. Private Shared Sub OnDataSent(ByVal sender As Object, ByVal e As DataTransferEventArgs) Console.WriteLine(e.Data.Length & " bytes sent") End Sub Private Shared Sub OnMessageDataChunkSent(ByVal sender As Object, _ ByVal e As SmtpMessageDataChunkSentEventArgs) Console.WriteLine(e.BytesJustSent & " bytes of the message " & _ e.MailMessage.MessageID & " sent") End Sub ' The actual code. Shared Sub Main(ByVal args As String()) Dim mailer As New Smtp ' Specify SMTP server and enable ESMTP authentication. ' Note, depending on your SMTP server settings, either ' "jdoe" or "jdoe@domain.com" should be used as user account name. mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret") ' Subscribe to events. AddHandler mailer.DataSent, AddressOf OnDataSent AddHandler mailer.MessageDataChunkSent, AddressOf OnMessageDataChunkSent ' Send a message (attach a big file to make the message be sent ' in multiple data chunks). mailer.To.AsString = "recipient1@domain1.com, recipient2@domain2.com" mailer.From.Email = "sender@domain.com" mailer.Subject = "Test message" mailer.BodyPlainText = "The message with attachment" mailer.AddAttachment("C:\bigfile.mdb") mailer.Send() Console.WriteLine("Message sent to: " & _ mailer.GetAcceptedRecipients().ToString()) End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace | DataSent