Sample code for 30+ languages & platforms
Dart

Unsubscribe from an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.Unsubscribe method, which removes the subscription to a mailbox. The mailbox itself and its messages are not deleted. This example unsubscribes from a mailbox.

Background: Unsubscribing simply drops a mailbox from the account's subscription list, so clients that show only subscribed folders will stop displaying it — the folder and everything in it remain on the server untouched. This is the counterpart to Subscribe, and is how you declutter a mailbox listing without deleting anything (deleting a folder is DeleteMailbox).

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // Demonstrates the Imap.Unsubscribe method, which removes the subscription to a mailbox.
  // The mailbox itself and its messages are not deleted.

  final imap = CkImap();

  imap.ssl = true;
  imap.port = 993;

  try {
    imap.connect('imap.example.com');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    imap.login('user@example.com', 'myPassword');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Remove the subscription to a mailbox (the mailbox is not deleted).
  try {
    imap.unsubscribe('Archive2026');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Unsubscribed from the mailbox.');

  try {
    imap.disconnect();
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }
}