Initializes a new instance of the ImapClient class and connects to the specified port on
the specified host, optionally using the Secure Socket Layer (SSL) security protocol and
attempts to authenticate with the server using the specified authentication method and
credentials.
Namespace: S22.ImapAssembly: S22.Imap (in S22.Imap.dll) Version: 3.6.0.0 (3.6.0.0)
Syntax
C# |
---|
public ImapClient( string hostname, int port, string username, string password, AuthMethod method = AuthMethod.Auto, bool ssl = false, RemoteCertificateValidationCallback validate = null ) |
Parameters
- hostname
- Type: System..::..String
The DNS name of the server to which you intend to connect.
- port
- Type: System..::..Int32
The port number of the server to which you intend to connect.
- username
- Type: System..::..String
The username with which to login in to the IMAP server.
- password
- Type: System..::..String
The password with which to log in to the IMAP server.
- method (Optional)
- Type: S22.Imap..::..AuthMethod
The requested method of authentication. Can be one of the values of the AuthMethod enumeration.
- ssl (Optional)
- Type: System..::..Boolean
Set to true to use the Secure Socket Layer (SSL) security protocol.
- validate (Optional)
- Type: System.Net.Security..::..RemoteCertificateValidationCallback
Delegate used for verifying the remote Secure Sockets Layer (SSL) certificate which is used for authentication. Can be null if not needed.
Examples
This example demonstrates how to connect and login to an IMAP server.
CopyC#

// Connect to Gmail's IMAP server on port 993 using SSL. ImapClient Client = null; try { Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Auto); // Check if the server supports IMAP IDLE. if(Client.Supports("IDLE")) Console.WriteLine("This server supports the IMAP4 IDLE specification"); else Console.WriteLine("This server does not support IMAP IDLE"); } catch(InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials"); } finally { // Release resources. if(Client != null) Client.Dispose(); }
Exceptions
Exception | Condition |
---|---|
System..::..ArgumentOutOfRangeException | The port parameter is not between MinPort and MaxPort. |
System..::..ArgumentNullException | The hostname parameter is null. |
S22.Imap..::..BadServerResponseException | An unexpected response has been received from the server upon connecting. |
System.IO..::..IOException | There was a failure writing to or reading from the network. |
S22.Imap..::..InvalidCredentialsException | The provided credentials were rejected by the server. |
System.Net.Sockets..::..SocketException | An error occurred while accessing the socket used for establishing the connection to the IMAP server. Use the ErrorCode property to obtain the specific error code. |
System.Security.Authentication..::..AuthenticationException | An authentication error occured while trying to establish a secure connection. |