ClientTerminatedException Class


Represents error that receiving email is cancelled by user.

System.Object
    System.Exception
        EAGetMail.ClientTerminatedException

[Visual Basic]
Public Class ClientTerminatedException
[C#]
public class ClientTerminatedException
[C++]
public ref class ClientTerminatedException
[JScript]
public class ClientTerminatedException

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Methods and Properties

Please refer to .NET Framework SDK System.Exception.

Example

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

[Visual Basic]
Imports EAGetMail
Module Module1
    Sub OnConnected( _
    ByVal sender As Object, _
    ByRef cancel As Boolean _
    )
        Console.Write("Connected")
        cancel = True ' sets cancel to false will throw the ClientTerminatedException
    End Sub

    Sub Main()
        ReceiveMail("myserver", "myuser", "mypass", False )
    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
        Try
            AddHandler oClient.OnConnected, AddressOf OnConnected
            
            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:\{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 expunge the emails from server permanently.
            oClient.Quit()
            
        Catch ep As ClientTerminatedException
            Console.WriteLine(ep.Message)
        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 Exception
            Console.WriteLine("System Error: {0}", ep.Message)
        End Try

        oClient.Close()
    End Sub
End Module

[C#]
using System;
using EAGetMail;

namespace Test
{
    class Class1
    {
        public static void OnConnected( 
            object sender,  
            ref bool cancel 
        )
        {
            Console.Write( "Connected\r\n" );
            cancel = true; // sets cancel to true will throw the ClientTerminatedException
        }

        [STAThread]
        static void Main(string[] args)
        {
            ReceiveMail("myserver", "myuser", "mypass", False );
        }

        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
            {
                oClient.OnConnected += new MailClient.OnConnectedEventHandler( OnConnected );

                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 expunge the emails from server permanently.
                oClient.Quit();
            }
            catch( ClientTerminatedException ep ) 
            {
                Console.WriteLine(ep.Message);
            }    
            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();
        }
    }
}

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

using namespace System;
using namespace EAGetMail;

System::Void OnConnected(Object ^sender, System::Boolean % cancel )
{
    Console::WriteLine("Connected");
    cancel = true; // sets cancel to true will throw the ClientTerminatedException   
}

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

    MailServer ^oServer  = gcnew 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
    {
        oClient->OnConnected += gcnew MailClient::OnConnectedEventHandler( &OnConnected );
    
        oClient->Connect(oServer);
        array<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", __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 expunge the emails from server permanently.
        oClient->Quit();
    }
    catch( ClientTerminatedException ^ep ) 
    {
        Console::WriteLine( ep->Message);
    }    
    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();
}

int main(array<System::String ^> ^args)
{
    ReceiveMail("myserver", "myuser", "mypass", false );
    return 0;
}