Mail ServiceConnect Async(String, Int 32, Secure Socket Options, 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 abstract Task ConnectAsync(
string host,
int port = 0,
SecureSocketOptions options = SecureSocketOptions.Auto,
CancellationToken cancellationToken = default
)Parameters
- host String
- The host name to connect to.
- port Int32 (Optional)
- The port to connect to. If the specified port is 0, then the default port will be used.
- options SecureSocketOptions (Optional)
- The secure socket options to when connecting.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
TaskAn asynchronous task context.
Implements
IMailServiceConnectAsync(String, Int32, SecureSocketOptions, CancellationToken)Remarks
Asynchronously establishes a connection to the specified mail server.
Exceptions
| ArgumentNullException | host is . |
| ArgumentOutOfRangeException | port is not between 0 and 65535. |
| 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. |