Click or drag to resize
MimeKit

SmtpClientDisconnectAsync Method

Asynchronously disconnect the service.

Namespace: MailKit.Net.Smtp
Assembly: MailKit (in MailKit.dll) Version: 4.3.0
Syntax
C#
public override Task DisconnectAsync(
	bool quit,
	CancellationToken cancellationToken = default
)

Parameters

quit  Boolean
If set to true, a QUIT command will be issued in order to disconnect cleanly.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

Task
An asynchronous task context.

Implements

IMailServiceDisconnectAsync(Boolean, CancellationToken)
IMailServiceDisconnectAsync(Boolean, CancellationToken)
Exceptions
ExceptionCondition
ObjectDisposedException The SmtpClient has been disposed.
Remarks
If quit is true, a QUIT command will be issued in order to disconnect cleanly.
Example
C#
public static void SendMessage (MimeMessage message)
{
    using (var client = new SmtpClient ()) {
        client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);

        client.Authenticate ("username", "password");

        client.Send (message);

        client.Disconnect (true);
    }
}
See Also