Dart Requires Chilkat v11.0.0+
Dart
List IMAP Mailboxes with Reference
Demonstrates how to list all sub-mailboxes within a specified context. In this case, we list all mailboxes under "INBOX.vendors".Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final imap = CkImap();
// Connect to an IMAP server.
// Use TLS
imap.ssl = true;
imap.port = 993;
try {
imap.connect('imap.example.com');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Login
try {
imap.login('admin@chilkatsoft.com', 'myPassword');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Get the list of mailboxes.
final refName = '';
final wildcardedMailbox = '*';
final subscribed = false;
final mboxes = CkMailboxes();
try {
imap.mbxList(subscribed, refName, wildcardedMailbox, mboxes);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
var i = 0;
while (i < mboxes.count) {
print(mboxes.getName(i));
i++;
}
// Sample output looks like this:
// INBOX.vendors.shareit
// INBOX.vendors.paypal
// INBOX.vendors.dell
// INBOX.vendors.inMotion
// INBOX.vendors.myhosting
// INBOX.vendors.peer1
// Disconnect from the IMAP server.
imap.disconnect();
}