MailKit.Net.Imap.ImapClient.Disconnect C# (CSharp) Method

Disconnect() public method

Disconnect the service.
If quit is true, a LOGOUT command will be issued in order to disconnect cleanly.
/// The has been disposed. ///
public Disconnect ( bool quit, CancellationToken cancellationToken = default(CancellationToken) ) : void
quit bool If set to true, a LOGOUT command will be issued in order to disconnect cleanly.
cancellationToken System.Threading.CancellationToken The cancellation token.
return void
		public override void Disconnect (bool quit, CancellationToken cancellationToken = default (CancellationToken))
		{
			CheckDisposed ();

			if (!engine.IsConnected)
				return;

			if (quit) {
				try {
					var ic = engine.QueueCommand (cancellationToken, null, "LOGOUT\r\n");

					engine.Wait (ic);

					ProcessResponseCodes (ic);
				} catch (OperationCanceledException) {
				} catch (ImapProtocolException) {
				} catch (ImapCommandException) {
				} catch (IOException) {
				}
			}

#if NETFX_CORE
			socket.Dispose ();
			socket = null;
#endif

			engine.Disconnect ();
			secure = false;
		}

Usage Example

Beispiel #1
1
		public static void DownloadMessages ()
		{
			using (var client = new ImapClient (new ProtocolLogger ("imap.log"))) {
				client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect);

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

				client.Inbox.Open (FolderAccess.ReadOnly);

				var uids = client.Inbox.Search (SearchQuery.All);

				foreach (var uid in uids) {
					var message = client.Inbox.GetMessage (uid);

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

				client.Disconnect (true);
			}
		}
All Usage Examples Of MailKit.Net.Imap.ImapClient::Disconnect