Click or drag to resize
MimeKit

Pop3ClientDisconnectAsync Method

Asynchronously disconnect the service.

Namespace: MailKit.Net.Pop3
Assembly: MailKit (in MailKit.dll) Version: 4.7.1
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 Pop3Client has been disposed.
Remarks
If quit is true, a QUIT command will be issued in order to disconnect cleanly.
Example
C#
public static void DownloadMessages ()
{
    using (var client = new Pop3Client ()) {
        client.Connect ("pop.gmail.com", 995, SecureSocketOptions.SslOnConnect);

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

        for (int i = 0; i < client.Count; i++) {
            var message = client.GetMessage (i);

            // write the message to a file
            message.WriteTo (string.Format ("{0}.msg", i));

            // mark the message for deletion
            client.DeleteMessage (i);
        }

        client.Disconnect (true);
    }
}
See Also