MailClient.OnSecuring Event


Occurs when the client is establishing the SSL connection.

[Visual Basic]
Public Event OnSecuring As OnSecuringEventHandler
Public Delegate Sub OnSecuringEventHandler( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
)
[C#]
public event OnSecuringEventHandler OnSecuring;
public delegate void OnSecuringEventHandler( 
     object sender, 
     ref bool cancel 
);
[C++]
public: __event OnSecuringEventHandler* OnSecuring;
public __gc __delegate void OnSecuringEventHandler( 
     Object* sender, 
     bool __gc *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.
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 connection 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.

[Visual Basic]
Imports EAGetMail

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

    Sub OnSecuring( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
    )
        Console.WriteLine("Securing ... ")
    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 OnReceivingDataStream( _
    ByVal sender As Object, _
    ByVal info As MailInfo, _
    ByVal received As Integer, _
    ByVal total As Integer, _
    ByRef cancel As Boolean _
    )
        Console.WriteLine(String.Format("{0}/{1} received", received, total))
    End Sub

    Sub OnConnected( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
    )
        Console.WriteLine("Connected")
    End Sub
    
    Public Sub ReceiveMail( _
    ByVal sServer As String, _
    ByVal sUserName As String, _
    ByVal sPassword As String, _
    ByVal bSSLConnection As Boolean)

        Dim oClient As New MailClient("TryIt")
        'To receive email from imap4 server, please change
        'ServerProtocol.Pop3 to ServerProtocol.Imap4 in MailServer constructor

        Dim oServer As New MailServer(sServer, _
            sUserName, sPassword, bSSLConnection, _
            ServerAuthType.AuthLogin, ServerProtocol.Pop3)


        'by default, the pop3 port is 110, imap4 port is 143, 
        'the pop3 ssl port is 995, imap4 ssl port is 993
        'you can also change the port like this
        'oServer.Port = 110

        '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.OnSecuring, AddressOf OnSecuring
        AddHandler oClient.OnReceivingDataStream, AddressOf OnReceivingDataStream

        Try
            oClient.Connect(oServer)
            Dim infos() As MailInfo = oClient.GetMailInfos()
            Dim count As Integer = infos.Length
            For i As Integer = 0 To count - 1
                Dim info As MailInfo = infos(i)
                Dim oMail As Mail = oClient.GetMail(info)
                'Save mail to local file
                oMail.SaveAs(String.Format("c:\temp\{0}.eml", i), True)
            Next

            For i As Integer = 0 To count - 1
                Dim info As MailInfo = infos(i)
                oClient.Delete(info)
            Next

            ' Delete method just mark the email as deleted, 
            ' Quit method pure the emails from server exactly.
            oClient.Quit()
        Catch ep As MailServerException
            'Message contains the information returned by mail server
            Console.WriteLine("Server Respond: {0}", ep.Message)
        Catch ep As System.Net.Sockets.SocketException
            Console.WriteLine("Socket Error: {0}", ep.Message)
        Catch ep As System.ComponentModel.Win32Exception
            Console.WriteLine("Win32 Error: {0}", ep.Message)
        Catch ep As Exception
            Console.WriteLine("System Error: {0}", ep.Message)
        End Try

        oClient.Close()
    End Sub
    
    Sub Main()
        ReceiveMail("myserver", "myuser", "mypassword", True)
    End Sub    
End Module

[C#]
using System;
using EAGetMail;

namespace Test
{
    class Class1
    {
        public static void OnQuit( 
            object sender, 
            ref bool cancel 
        )
        {
            Console.WriteLine( "Disconnecting ... " );
        }

        public static void OnSecuring( 
            object sender, 
            ref bool cancel 
        )
        {
            Console.WriteLine( "Securing ... " );
        }

        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 OnReceivingDataStream( 
            object sender, 
            MailInfo info,
            int received, 
            int total, 
            ref bool cancel 
        )
        {
            Console.WriteLine( String.Format( "{0}/{1} received", received, total ));
        }
        
        public static void OnConnected( 
            object sender,  
            ref bool cancel 
        )
        {
            Console.WriteLine( "Connected" );
        }

        public static void ReceiveMail( 
            string sServer, 
            string sUserName,
            string sPassword,
            bool bSSLConnection)
        {
            MailClient oClient = new MailClient("TryIt");
            //To receive email from imap4 server, please change
            //ServerProtocol.Pop3 to ServerProtocol.Imap4 in MailServer constructor

            MailServer oServer  = new MailServer(sServer, 
                sUserName, sPassword, bSSLConnection, 
                ServerAuthType.AuthLogin, ServerProtocol.Pop3);

            //by default, the pop3 port is 110, imap4 port is 143, 
            //the pop3 ssl port is 995, imap4 ssl port is 993
            //you can also change the port like this
            //oServer.Port = 110;
            try
            {
                //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.OnSecuring += new MailClient.OnSecuringEventHandler( OnSecuring );
                oClient.OnReceivingDataStream += new MailClient.OnReceivingDataStreamEventHandler( OnReceivingDataStream ); 

                oClient.Connect(oServer);
                MailInfo [] infos = oClient.GetMailInfos();
                int count = infos.Length;
                for( int i = 0; i < count; i++ )
                {
                    MailInfo info = infos[i];
                    Mail oMail = oClient.GetMail(info);
                    //Save mail to local    file
                    oMail.SaveAs(String.Format("c:\\{0}.eml", i), true);
                }

                for( int i = 0; i < count; i++ )
                {
                    MailInfo info = infos[i];
                    oClient.Delete(info);
                }
            
                // Delete method just mark the email as deleted, 
                // Quit method pure the emails from server exactly.
                oClient.Quit();
            }
            catch( MailServerException ep ) 
            {
                //Message contains the information returned by mail server
                Console.WriteLine("Server Respond: {0}", ep.Message);
            }
            catch( System.Net.Sockets.SocketException ep ) 
            {
                Console.WriteLine("Socket Error: {0}", ep.Message);
            }
            catch( Exception ep ) 
            {
                Console.WriteLine("System Error: {0}", ep.Message);
            }

            oClient.Close();
        }
        
        [STAThread]
        static void Main(string[] args)
        {
            ReceiveMail( "myserver", "myusername", "mypassword", true );
        }
    }
}

[C++]
#include "stdafx.h"
#using <mscorlib.dll>

using namespace System;
using namespace EAGetMail;

public __gc class MailClientEventHandler
{
public:
static void OnQuit( 
            Object* sender, 
            bool __gc *cancel 
            )
{
    Console::WriteLine( S"Disconnecting ... " );
}

static void OnSecuring( 
                Object* sender, 
                bool __gc *cancel 
                )
{
    Console::WriteLine( S"Securing ... " );
}

static void OnAuthorized( 
                  Object* sender, 
                  bool __gc *cancel 
                  )
{
    Console::WriteLine( S"Authorized" );
}

static void OnIdle( 
            Object* sender, 
            bool __gc *cancel 
            )
{
    //Application.DoEvents();
}

static void OnReceivingDataStream( 
                         Object* sender,
                         MailInfo *info, 
                         int received, 
                         int total, 
                         bool __gc *cancel 
                         )
{
    Console::WriteLine( S"{0}/{1} received", __box(received), __box(total));
}

static void OnConnected( 
                 Object* sender,  
                 bool __gc *cancel 
                 )
{
    Console::WriteLine( S"Connected" );
}
};

Void ReceiveMail( 
    String *sServer, 
    String *sUserName,
    String *sPassword,
    bool bSSLConnection)
{
    MailClient *oClient = new MailClient(S"TryIt");
    //To receive email from imap4 server, please change
    //ServerProtocol::Pop3 to ServerProtocol::Imap4 in MailServer constructor

    MailServer *oServer  = new MailServer(sServer, 
        sUserName, sPassword, bSSLConnection, 
        ServerAuthType::AuthLogin, ServerProtocol::Pop3);

    //by default, the pop3 port is 110, imap4 port is 143, 
    //the pop3 ssl port is 995, imap4 ssl port is 993
    //you can also change the port like this
    //oServer->Port = 110;
    try
    {
        //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->OnSecuring += new MailClient::OnSecuringEventHandler( NULL, MailClientEventHandler::OnSecuring );
        oClient->OnAuthorized += new MailClient::OnAuthorizedEventHandler( NULL, MailClientEventHandler::OnAuthorized );
        oClient->OnIdle += new MailClient::OnIdleEventHandler( NULL, MailClientEventHandler::OnIdle );
        oClient->OnQuit += new MailClient::OnQuitEventHandler( NULL, MailClientEventHandler::OnQuit );
        oClient->OnConnected += new MailClient::OnConnectedEventHandler( NULL, MailClientEventHandler::OnConnected );
        oClient->OnReceivingDataStream += new MailClient::OnReceivingDataStreamEventHandler( NULL, MailClientEventHandler::OnReceivingDataStream );

        oClient->Connect(oServer);
        MailInfo *infos[]= oClient->GetMailInfos();
        int count = infos->Length;
        for( int i = 0; i < count; i++ )
        {
            MailInfo *info = infos[i];
            Mail *oMail = oClient->GetMail(info);
            //Save mail to local file
            oMail->SaveAs(String::Format(S"c:\\{0}.eml", __box(i)), true);
        }

        for( int i = 0; i < count; i++ )
        {
            MailInfo *info = infos[i];
            oClient->Delete(info);
        }
    
        // Delete method just mark the email as deleted, 
        // Quit method pure the emails from server exactly.
        oClient->Quit();
    }
    catch( MailServerException *ep ) 
    {
        //Message contains the information returned by mail server
        Console::WriteLine( S"Server Respond: {0}", ep->Message);
    }
    catch( System::Net::Sockets::SocketException *ep ) 
    {
        Console::WriteLine( S"Socket Error: {0}", ep->Message);
    }
    catch( Exception *ep ) 
    {
        Console::WriteLine( S"System Error: {0}", ep->Message);
    }

    oClient->Close();
}

int _tmain()
{
    ReceiveMail( S"myserver", S"myuser", S"mypassword", true );
    return 0;
}