MailBee.NET Objects 7.2

Imap.LowLevelDataSent Event

Occurs when data is sent to the connected socket.

public event DataTransferEventHandler LowLevelDataSent;

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

If the transmission channel is encrypted, this event will be raised each time an encrypted chunk of data is successfully sent. Thus, this event can be used to record the data which is actually sent to the network.

The typical use of this property is to calculate the network traffic produced during the IMAP4 session. SSL encryption increases the length of the transmitted data blocks, thus it's more accurate to calculate traffic by counting the length of data actually transmitted over the network.

If the transmission channel is not encrypted or otherwise scrambled, this property is equivalent to DataSent.

Example

This sample calculates all outgoing traffic to the server during the IMAP4 session, and prints the result into console.

[C#]
using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

class Sample
{
    // Total bytes sent counter.
    private static int _totalBytes = 0;

    // LowLevelDataSent event handler.
    private static void OnLowLevelDataSent(object sender, DataTransferEventArgs e)
    {
        // Increment the counter.
        _totalBytes += e.Data.Length;
    }

    // The actual code.
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Subscribe to the LowLevelDataSent event.
        imp.LowLevelDataSent += new DataTransferEventHandler(OnLowLevelDataSent);

        // Do something which would produce some network traffic.
        imp.Connect("mail.domain.com");
        imp.Login("jdoe", "secret");
        imp.SelectFolder("Inbox");
        MailMessageCollection msgs =
            imp.DownloadMessageHeaders(Imap.AllMessages, false);
        imp.Disconnect();

        // Print the total number of bytes previously sent to the server.
        Console.WriteLine(_totalBytes + " bytes sent in all");
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail
Imports MailBee.Mime

Module Sample
    ' Total bytes sent counter.
    Dim _totalBytes As Integer = 0

    ' LowLevelDataSent event handler.
    Private Sub OnLowLevelDataSent(ByVal sender As Object, ByVal e As DataTransferEventArgs)
        ' Increment the counter.
        _totalBytes += e.Data.Length
    End Sub

    ' The actual code.
    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Subscribe to the LowLevelDataSent event.
        AddHandler imp.LowLevelDataSent, AddressOf OnLowLevelDataSent

        ' Do something which would produce some network traffic.
        imp.Connect("mail.domain.com")
        imp.Login("jdoe", "secret")
        imp.SelectFolder("Inbox")
        Dim msgs As MailMessageCollection = imp.DownloadMessageHeaders(Imap.AllMessages, False)
        imp.Disconnect()

        ' Print the total number of bytes previously sent to the server.
        Console.WriteLine(_totalBytes & " bytes sent in all")
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | DataSent