 | MailServiceConnect Method (Uri, CancellationToken) |
Establish a connection to the specified mail server.
Namespace:
MailKit
Assembly:
MailKit (in MailKit.dll) Version: 3.0.0
Syntaxpublic void Connect(
Uri uri,
CancellationToken cancellationToken = default
)
Parameters
- uri
- Type: SystemUri
The server URI. - cancellationToken (Optional)
- Type: System.ThreadingCancellationToken
The cancellation token.
Exceptions
Remarks
Establishes a connection to the specified mail server.
Examplespublic static void SendMessage (MimeMessage message)
{
using (var client = new SmtpClient ()) {
var uri = new Uri ("smtps://smtp.gmail.com:465");
client.Connect (uri);
client.Authenticate ("username", "password");
client.Send (message);
client.Disconnect (true);
}
}
See Also