MailBee.NET Objects 4.0

Imap.DataReceived Event

Occurs when data is received from the IMAP4 server.

public event DataTransferEventHandler DataReceived;

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 LowLevelDataReceived event, occurrence of this event indicates receiving IMAP4-related data only. 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.

Unlike EnvelopeDataChunkReceived event, DataReceived will be raised when any IMAP4-related data is received, while EnvelopeDataChunkReceived event is raised only when FETCH response (containing IMAP4 envelopes, body structures, message data, etc) is downloaded.

Note   This event is also raised when zero-length data is received from the server. When the server sends zero-length data portion, it means the server closed the connection. This normally happens after Disconnect method was called.

Example

This sample prints all the data received from the server during IMAP4 session into console.

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

class Sample
{
    // DataReceived event handler.
    private static void OnDataReceived(object sender, DataTransferEventArgs e)
    {
        Console.WriteLine("[" + System.Text.Encoding.Default.GetString(e.Data) + "]");
    }

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

        // Subscribe to the DataReceived event.
        imp.DataReceived += new DataTransferEventHandler(OnDataReceived);

        // Do something which would produce some network traffic.
        imp.Connect("mail.domain.com");
        imp.Login("jdoe@domain.com", "secret");
        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    ' DataReceived event handler.
    Private Sub OnDataReceived(ByVal sender As Object, ByVal e As DataTransferEventArgs)
        Console.WriteLine("[" & System.Text.Encoding.Default.GetString(e.Data) & "]")
    End Sub

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

        ' Subscribe to the DataReceived event.
        AddHandler imp.DataReceived, AddressOf OnDataReceived

        ' Do something which would produce some network traffic.
        imp.Connect("mail.domain.com")
        imp.Login("jdoe@domain.com", "secret")
        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | EnvelopeDataChunkReceived | LowLevelDataReceived