Click or drag to resize
MimeKit

MailServiceConnectAsync Method (Stream, String, Int32, SecureSocketOptions, CancellationToken)

Asynchronously establish a connection to the specified mail server using the provided stream.

Namespace:  MailKit
Assembly:  MailKit (in MailKit.dll) Version: 2.3.0
Syntax
C#
public abstract Task ConnectAsync(
	Stream stream,
	string host,
	int port = 0,
	SecureSocketOptions options = SecureSocketOptions.Auto,
	CancellationToken cancellationToken = null
)

Parameters

stream
Type: System.IOStream
The stream 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.

Return Value

Type: Task
An asynchronous task context.

Implements

IMailServiceConnectAsync(Stream, String, Int32, SecureSocketOptions, CancellationToken)
Exceptions
ExceptionCondition
ArgumentNullException

stream is null.

-or-

host is null.

ArgumentOutOfRangeExceptionport is not between 0 and 65535.
ArgumentException The host is a zero-length string.
InvalidOperationException The IMailService is already connected.
OperationCanceledException The operation was canceled via the cancellation token.
IOException An I/O error occurred.
CommandException The command was rejected by the mail server.
ProtocolException The server responded with an unexpected token.
Remarks

Asynchronously establishes a connection to the specified mail server using the provided stream.

If a successful connection is made, the AuthenticationMechanisms property will be populated.

See Also