MailClient.OnSendingDataStream Event


Occurs when the client is sending the e-mail data (Append) to the IMAP4 server.

[Visual Basic]
Public Event OnSendingDataStream As OnSendingDataStreamEventHandler
Public Delegate Sub OnSendingDataStreamEventHandler(_ ByVal sender As Object,
    _ ByVal sent As Integer, _ ByVal total As Integer, _ ByRef cancel
    As Boolean _)
[C#]
public event OnSendingDataStreamEventHandler OnSendingDataStream;
public delegate void OnSendingDataStreamEventHandler(object sender, int
    sent, int total, ref bool cancel);
[C++]
public: __event OnSendingDataStreamEventHandler^ OnSendingDataStream;
public __gc __delegate void OnSendingDataStreamEventHandler(Object^ sender,
    int sent, int total, bool % cancel);
[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

sender
The source (MailClient instance) of the event.
sent
The number of bytes sent to the IMAP4 server.
total
The number of bytes in email content.
cancel
Gets or sets a value indicating whether the task should be canceled.

Remarks

If cancel parameter is set to true in the event, the client terminates the task immediately and a ClientTerminatedException exception will be thrown.

Example

[Visual Basic, C#, C++] To get the full samples of EAGetMail, please refer to Samples section.

[VB - Append Email]
Imports EAGetMail

Module Module1
    Sub OnSendingDataStream( _
    ByVal sender As Object, _
    ByVal sent As Integer, _
    ByVal total As Integer, _
    ByRef cancel As Boolean _
 )
        Console.WriteLine(String.Format("{0}/{1} sent", sent, total))
    End Sub

    Sub OnQuit( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
 )
        Console.WriteLine("Disconnecting ... ")
    End Sub

    Sub OnAuthorized( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
 )
        Console.WriteLine("Authorized")
    End Sub

    Sub OnIdle( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
 )
        'Application.DoEvents()
    End Sub

    Sub OnConnected( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
 )
        Console.WriteLine("Connected")
    End Sub
    
    Sub AppendEmail(ByVal emlFile As String, _
    ByVal server As String, _
    ByVal user As String, _
    ByVal password As String)
        Try
            Dim oMail As New Mail("TryIt")
            oMail.Load(emlFile, False)

            Dim oClient As New MailClient("TryIt")
            Dim oServer As New MailServer(server, user, password, ServerProtocol.Imap4)

            'Catching the following events is not necessary, 'just make the
                application more user friendly. 'If you use the object in asp.net/windows service
                or non-gui application, 'You need not to catch the following events. 'To learn more
                detail, please refer to the code in EAGetMail EventHandler region
            
            AddHandler oClient.OnAuthorized, AddressOf OnAuthorized
            AddHandler oClient.OnConnected, AddressOf OnConnected
            AddHandler oClient.OnIdle, AddressOf OnIdle
            AddHandler oClient.OnQuit, AddressOf OnQuit
            AddHandler oClient.OnSendingDataStream, AddressOf OnSendingDataStream

            oClient.Connect(oServer)
            Dim folders() As Imap4Folder = oClient.Imap4Folders
            Dim count As Integer = folders.Length
            For i As Integer = 0 To count - 1
                Dim folder As Imap4Folder = folders(i)
                If String.Compare("Inbox", folder.Name, True) = 0 Then
                    'appends this email to "Inbox" folder
                    oClient.Append(folder, oMail.Content)
                    Exit For
                End If
            Next
            oClient.Logout()
        Catch ep As Exception
            Console.WriteLine(ep.Message)
        End Try
    End Sub
    
    Sub Main()
        AppendEmail("c:\test.eml", "myserver", "myuser", "mypassword")
    End Sub    
End Module


[C# - Append Email] using System; using EAGetMail; namespace Test { class Class1 { public static void OnSendingDataStream( object sender, int sent, int total, ref bool cancel ) { Console.WriteLine(String.Format("{0}/{1} sent", sent, total)); } public static void OnQuit( object sender, ref bool cancel ) { Console.WriteLine("Disconnecting ... "); } public static void OnAuthorized( object sender, ref bool cancel ) { Console.WriteLine("Authorized"); } public static void OnIdle( object sender, ref bool cancel ) { //Application.DoEvents(); } public static void OnConnected( object sender, ref bool cancel ) { Console.WriteLine("Connected"); } public static void AppendEmail(string emlFile, string server, string user, string password) { try { Mail oMail = new Mail("TryIt"); oMail.Load(emlFile, false); MailClient oClient = new MailClient("TryIt"); MailServer oServer = new MailServer(server, user, password, ServerProtocol.Imap4); oClient.Connect(oServer); //Catching the following events is not necessary, //just make the application more user friendly. //If you use the object in asp.net/windows service or non-gui application, //You need not to catch the following events. //To learn more detail, please refer to the code in EAGetMail EventHandler region oClient.OnAuthorized += new MailClient.OnAuthorizedEventHandler(OnAuthorized); oClient.OnConnected += new MailClient.OnConnectedEventHandler(OnConnected); oClient.OnIdle += new MailClient.OnIdleEventHandler(OnIdle); oClient.OnQuit += new MailClient.OnQuitEventHandler(OnQuit); oClient.OnSendingDataStream += new MailClient.OnSendingDataStreamEventHandler(OnSendingDataStream); Imap4Folder [] folders = oClient.Imap4Folders; int count = folders.Length; for(int i = 0; i < count; i++) { Imap4Folder folder = folders[i]; if(String.Compare("INBOX", folder.Name, true) == 0) { //appends this email to "Inbox" folder oClient.Append(folder, oMail.Content); break; } } oClient.Logout(); } catch(Exception ep) { Console.WriteLine(ep.Message); } } [STAThread] static void Main(string[] args) { AppendEmail("c:\\test.eml", "myserver", "myusername", "mypassword"); } } }
[C++C/CLI - Append Email] #include "stdafx.h" using namespace System; using namespace System::IO; using namespace EAGetMail; //add EAGetMail namespace System::Void OnSendingDataStream( Object^ sender, int sent, int total, System::Boolean % cancel ) { Console::WriteLine("{0}/{1} sent", sent, total); } System::Void OnConnected(Object ^sender, System::Boolean % cancel) { Console::WriteLine("Connected"); } System::Void OnQuit(Object ^sender, System::Boolean % cancel) { Console::WriteLine("Quit"); } System::Void OnIdle(Object ^sender, System::Boolean % cancel) { //Application::DoEvents(); } System::Void OnAuthorized(Object ^sender, System::Boolean % cancel) { Console::WriteLine("Authorized"); } System::Void OnSecuring(Object ^sender, System::Boolean % cancel) { Console::WriteLine("Securing..."); } System::Void AppendEmail(String^ emlFile, String^ server, String^ user, String^ password) { try { Mail^ oMail = gcnew Mail("TryIt"); oMail->Load(emlFile, false); MailClient ^oClient = gcnew MailClient("TryIt"); MailServer ^oServer = gcnew MailServer(server, user, password, ServerProtocol::Imap4); //Catching the following events is not necessary, //just make the application more user friendly. //If you use the object in asp.net/windows service or non-gui application, //You need not to catch the following events. //To learn more detail, please refer to the code in EAGetMail EventHandler region oClient->OnAuthorized += gcnew MailClient::OnAuthorizedEventHandler(&OnAuthorized); oClient->OnConnected += gcnew MailClient::OnConnectedEventHandler(&OnConnected); oClient->OnIdle += gcnew MailClient::OnIdleEventHandler(&OnIdle); oClient->OnSecuring += gcnew MailClient::OnSecuringEventHandler(&OnSecuring); oClient->OnSendingDataStream += gcnew MailClient::OnSendingDataStreamEventHandler(&OnSendingDataStream); oClient->OnQuit += gcnew MailClient::OnQuitEventHandler(&OnQuit); oClient->Connect(oServer); array<Imap4Folder^> ^folders = oClient->Imap4Folders; int count = folders->Length; for(int i = 0; i < count; i++) { Imap4Folder ^folder = folders[i]; if(String::Compare("INBOX", folder->Name, true) == 0) { //appends email to "INBOX" oClient->Append(folder, oMail->Content); break; } } oClient->Logout(); } catch(Exception ^ep) { Console::WriteLine(ep->Message); } } int main(array<System::String ^> ^args) { AppendEmail("c:\\test.eml", "myserver", "myuser", "mypassword"); return 0; }