Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

List Email UIDs

List the UIDs of each email in a mailbox.

Chilkat Dart Downloads

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

void main() {
  final imap = CkImap();

  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  // Connect to an IMAP server.
  // Use TLS
  imap.ssl = true;
  imap.port = 993;
  try {
    imap.connect('MY-IMAP-DOMAIN');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Login
  try {
    imap.login('MY-IMAP-LOGIN', 'MY-IMAP-PASSWORD');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Select an IMAP mailbox
  try {
    imap.selectMailbox('Inbox');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Get the message IDs of all the emails in the mailbox
  // We can choose to fetch UIDs or sequence numbers.
  final fetchUids = true;
  final messageSet = CkMessageSet();
  try {
    imap.queryMbx('ALL', fetchUids, messageSet);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  var i = 0;
  final n = messageSet.count;
  while (i < n) {
    print(messageSet.getId(i));
    i++;
  }

  // Disconnect from the IMAP server.
  imap.disconnect();
}