Click or drag to resize
MimeKit

MailServiceConnectAsync(String, Int32, Boolean, CancellationToken) Method

Asynchronously establish a connection to the specified mail server.

Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 4.3.0
Syntax
C#
public Task ConnectAsync(
	string host,
	int port,
	bool useSsl,
	CancellationToken cancellationToken = default
)

Parameters

host  String
The host to connect to.
port  Int32
The port to connect to. If the specified port is 0, then the default port will be used.
useSsl  Boolean

Field Value

Task
true if the client should make an SSL-wrapped connection to the server; otherwise,

Field Value

Task
false.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

Task
An asynchronous task context.

Implements

IMailServiceConnectAsync(String, Int32, Boolean, CancellationToken)
Exceptions
ExceptionCondition
ArgumentNullException The host is null.
ArgumentOutOfRangeExceptionport is out of range (

Field Value

Task
0 to

Field Value

Task
65535, inclusive).
ArgumentException The host is a zero-length string.
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.
Remarks

Asynchronously establishes a connection to the specified mail server.

Note  Note

The useSsl argument only controls whether or not the client makes an SSL-wrapped connection. In other words, even if the useSsl parameter is false, SSL/TLS may still be used if the mail server supports the STARTTLS extension.

To disable all use of SSL/TLS, use the ConnectAsync(String, Int32, SecureSocketOptions, CancellationToken) overload with a value of SecureSocketOptions.None instead.

See Also