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