Click or drag to resize
MimeKit

ImapClientConnect Method (Socket, String, Int32, SecureSocketOptions, CancellationToken)

Establish a connection to the specified IMAP or IMAP/S server using the provided socket.

Namespace:  MailKit.Net.Imap
Assembly:  MailKit (in MailKit.dll) Version: 2.10.0
Syntax
C#
public override void Connect(
	Socket socket,
	string host,
	int port = 0,
	SecureSocketOptions options = SecureSocketOptions.Auto,
	CancellationToken cancellationToken = null
)

Parameters

socket
Type: System.Net.SocketsSocket
The socket to use for the connection.
host
Type: SystemString
The host name to connect to.
port (Optional)
Type: SystemInt32
The port to connect to. If the specified port is 0, then the default port will be used.
options (Optional)
Type: MailKit.SecuritySecureSocketOptions
The secure socket options to when connecting.
cancellationToken (Optional)
Type: System.ThreadingCancellationToken
The cancellation token.

Implements

IMailServiceConnect(Socket, String, Int32, SecureSocketOptions, CancellationToken)
IMailServiceConnect(Socket, String, Int32, SecureSocketOptions, CancellationToken)
Exceptions
ExceptionCondition
ArgumentNullException

socket is null.

-or-

host is null.

ArgumentOutOfRangeExceptionport is not between 0 and 65535.
ArgumentException

socket is not connected.

-or-

The host is a zero-length string.

ObjectDisposedException The ImapClient has been disposed.
InvalidOperationException The ImapClient is already connected.
NotSupportedExceptionoptions was set to StartTls and the IMAP server does not support the STARTTLS extension.
OperationCanceledException The operation was canceled via the cancellation token.
IOException An I/O error occurred.
ImapCommandException An IMAP command failed.
ImapProtocolException An IMAP protocol error occurred.
Remarks

Establishes a connection to the specified IMAP or IMAP/S server using the provided socket.

If the options has a value of Auto, then the port is used to determine the default security options. If the port has a value of 993, then the default options used will be SslOnConnect. All other values will use StartTlsWhenAvailable.

Once a connection is established, properties such as AuthenticationMechanisms and Capabilities will be populated.

Note Note
With the exception of using the port to determine the default SecureSocketOptions to use when the options value is Auto, the host and port parameters are only used for logging purposes.
See Also