MailServiceConnectAsync(Uri, CancellationToken) Method

Asynchronously establish a connection to the specified mail server.

Definition

Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public Task ConnectAsync(
	Uri uri,
	CancellationToken cancellationToken = default
)

Parameters

uri  Uri
The server URI.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

Task
An asynchronous task context.

Remarks

Asynchronously establishes a connection to the specified mail server.

Exceptions

ArgumentNullException The uri is .
ArgumentException The uri is not an absolute URI.
ObjectDisposedException The MailService has been disposed.
InvalidOperationException The MailService is already connected.
OperationCanceledException The operation was canceled via the cancellation token.
SocketException A socket error occurred trying to connect to the remote host.
IOException An I/O error occurred.
ProtocolException A protocol error occurred.

See Also