IMail ServiceConnect(String, Int 32, Boolean, Cancellation Token) Method
Establish a connection to the specified mail server.
Definition
Namespace: MailKit
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
void Connect(
string host,
int port,
bool useSsl,
CancellationToken cancellationToken = default
)Parameters
- host String
- The host name 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.
Remarks
Establish a connection to the specified mail server.
If a successful connection is made, the AuthenticationMechanisms property will be populated.
Exceptions
| ArgumentNullException | host is . |
| ArgumentOutOfRangeException | port 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. |