MailBee.NET Objects 4.0

Smtp.DataSent Event

Occurs when data is sent to the network.

public event DataTransferEventHandler DataSent;

Event Data

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.

Remarks

Unlike LowLevelDataSent event, occurrence of this event indicates sending unencrypted data only. For instance, if the transmission channel is SSL-encrypted, LowLevelDataSent event indicates sending of any portion of encrypted data, while DataSent will be raised later to indicate the entire request (which was previously sent as one or several encrypted data chunks) has been sent. If the transmission channel is not encrypted or otherwise scrambled, DataSent and LowLevelDataSent are equivalent.

Example

This sample prints all the data sent to the server during SMTP session into console.

[C#]
using System;
using MailBee;
using MailBee.SmtpMail;

class Sample
{
    // DataSent event handler.
    private static void OnDataSent(object sender, DataTransferEventArgs e)
    {
        // Ignore POP3 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();

        // Specify SMTP server and enable POP-before-SMTP authentication.
        SmtpServer server = new SmtpServer("mail.domain.com");
        server.AuthPopBeforeSmtp = true;
        server.AccountName = "jdoe";
        server.Password = "secret";
        mailer.SmtpServers.Add(server);

        // Subscribe to the DataSent event.
        mailer.DataSent += new DataTransferEventHandler(OnDataSent);

        // Produce some POP3 and SMTP traffic by connecting in POP-before-SMTP mode.
        mailer.Connect();
        mailer.Hello();
        mailer.Disconnect();
    }
}
[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)
        ' Ignore POP3 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

        ' Specify SMTP server and enable POP-before-SMTP authentication.
        Dim server As New SmtpServer
        server = New SmtpServer("mail.domain.com")
        server.AuthPopBeforeSmtp = True
        server.AccountName = "jdoe"
        server.Password = "secret"
        mailer.SmtpServers.Add(server)

        ' Subscribe to the DataSent event.
        AddHandler mailer.DataSent, AddressOf OnDataSent

        ' Produce some POP3 and SMTP traffic by connecting in POP-before-SMTP mode.
        mailer.Connect()
        mailer.Hello()
        mailer.Disconnect()
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace | MessageDataChunkSent | LowLevelDataSent