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.

Namespace: S22.Imap
Assembly: S22.Imap (in S22.Imap.dll) Version: 3.6.0.0 (3.6.0.0)

Syntax

C#
public ImapClient(
	string hostname,
	int port = 143,
	bool ssl = false,
	RemoteCertificateValidationCallback validate = null
)

Parameters

hostname
Type: System..::..String
The DNS name of the server to which you intend to connect.
port (Optional)
Type: System..::..Int32
The port number of the server to which you intend to connect.
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 shows how to establish a connection with an IMAP server and print out the IMAP options, which the server supports.
CopyC#
// Connect to Gmail's IMAP server on port 993 using SSL.
ImapClient Client = new ImapClient("imap.gmail.com", 993, true);

// Print out the server's capabilities.
foreach(string s in Client.Capabilities())
    Console.WriteLine(s);

Client.Dispose();

Exceptions

ExceptionCondition
System..::..ArgumentOutOfRangeExceptionThe port parameter is not between MinPort and MaxPort.
System..::..ArgumentNullExceptionThe hostname parameter is null.
S22.Imap..::..BadServerResponseExceptionAn unexpected response has been received from the server upon connecting.
System.IO..::..IOExceptionThere was a failure writing to or reading from the network.
System.Net.Sockets..::..SocketExceptionAn 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..::..AuthenticationExceptionAn authentication error occured while trying to establish a secure connection.

See Also