Mail ServiceConnect Async(String, Int 32, Boolean, Cancellation Token) Method
Asynchronously establish a connection to the specified mail server.
Definition
Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
An asynchronous task context.
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
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
- if the client should make an SSL-wrapped connection to the server; otherwise, .
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
TaskAn asynchronous task context.
Implements
IMailServiceConnectAsync(String, Int32, Boolean, CancellationToken)Remarks
Asynchronously establishes a connection to the specified mail server.
Exceptions
| ArgumentNullException | The host is . |
| ArgumentOutOfRangeException |
port is out of range (Field ValueTask0 to Field ValueTask65535, 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. |